sql - Returning all data in one row -
in postgresql database, have multiple reference data tables. example:
- gender(id:serial, name:varchar) - sexuality(id:serial, name:varchar) - location(id:serial,name:varchar)
to retrieve of information in of tables doing 3 separate select statements. example:
- "select name gender; - "select name sexuality; - "select name location;
how can make 1 call returns 1 row this:
referencedata(allgenders:varchar[], allsexualities:varchar[], alllocations:varchar[])
i able able client side -->
var genders = results.row[0].allgenders; gender in genders { print(gender); }
you can use array_agg
aggragate function combine values multiple rows single array, e.g.
select array_agg(name) gender
will return genders single array. if want information 3 tables @ once, can that:
select (select array_agg(name) gender), (select array_agg(name) sexuality), (select array_agg(name) location);
Comments
Post a Comment