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?

8
  • Is that really your entire query? You don't have any WHERE or other clause in addition to this?
    – Lukas Eder
    Commented Jan 9, 2017 at 13:31
  • 4
    This should work. Are you sure the table really has data in it? Commented Jan 9, 2017 at 13:31
  • @GordonLinoff Yes the table has data
    – LSG
    Commented Jan 9, 2017 at 15:38
  • @LukasEder I don't have any WHERE clause
    – LSG
    Commented Jan 9, 2017 at 15:38
  • 2
    It should works: sqlfiddle.com/#!15/26e97/1/1 How did you check result? Commented Jan 9, 2017 at 21:43

1 Answer 1

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.