When using array_agg or array_string, the array returns empty above a certain size.
SELECT array_agg(x.id) FROM (SELECT id FROM table LIMIT 500) x
- this works and returns an array.
but this query : SELECT array_agg(x.id) FROM (SELECT id FROM table LIMIT 667) x
Doesn't work. it returns an empty array.
i'm pretty sure this doesn't reach the limitation size of an array. Any ideas why is this happening?
PostgreSQL ARRAY_AGG() function is an aggregate function that accepts a set of values and returns an array where each value in the input set is assigned to an element of the array. Syntax: ARRAY_AGG(expression [ORDER BY [sort_expression {ASC | DESC}], [...]) The ORDER BY clause is an voluntary clause.
Returns the input values, pivoted into an ARRAY. If the input is empty, an empty ARRAY is returned.
Like most other relational database products, PostgreSQL supports aggregate functions. An aggregate function computes a single result from multiple input rows. For example, there are aggregates to compute the count , sum , avg (average), max (maximum) and min (minimum) over a set of rows.
To define a new aggregate function, one selects a data type for the state value, an initial value for the state, and a state transition function. The state transition function takes the previous state value and the aggregate's input value(s) for the current row, and returns a new state value.
the issue here was not Postgresql, but rather the client I was using.
pgAdmin III
doesn't display the content of array over a certain size. about 4.5k.
when using psql
one doesn't encounter the same issue.
the the UI of pgAdmin
there is an option to set "Max characters per column" and it was set to 256 in my case, which makes little sense.
but you copy & paste the array that looks empty into notepad you'll find the all the data is there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With