0

I have an integer type column named as start. I want to make an array by the values of this column. It seemed to be very easy and I used array_agg(), but it is giving empty array as output. Following is my column data

start
 1
 2
 11
 5
 .
 .
 . (and so on)

And following is my query used to make the array:

select array_agg(start) as start_array from table1;

Why is it giving empty array?

LSG
  • 213
  • 3
  • 14

1 Answers1

1

It's not

There is no way that this can return empty unless there are no rows. Perhaps a JOIN or a WHERE clause is wrong and you have 0-rows?

Also as a micro-optimization if your query is this simple,

select array_agg(start) as start_array from table1;

Then it's probably better written with the ARRAY() constructor...

SELECT ARRAY(SELECT start FROM table1) AS start_array;
Community
  • 1
  • 1
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468