HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Put Postgres query result in array

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
resultpostgresarrayqueryput

Problem

How can I put an sql query result in a string array with Postgres?
I have some attributes in the column 'zone' of the table 'mytable' and I must put them all in a String[] areas;
This is my first request, sorry if I made some format mistake.

Solution

You can use an array constructor:

select array(
select zone
from mytable) 
as areas;

Code Snippets

select array(
select zone
from mytable) 
as areas;

Context

StackExchange Database Administrators Q#100813, answer score: 7

Revisions (0)

No revisions yet.