Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limitation of array_agg in Postgresql 9.1

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?

like image 767
Ereli Avatar asked Sep 13 '12 07:09

Ereli


People also ask

What is Array_agg in PostgreSQL?

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.

What does Array_agg return?

Returns the input values, pivoted into an ARRAY. If the input is empty, an empty ARRAY is returned.

What is an aggregate function Postgres?

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.

How do I create aggregate function in PostgreSQL?

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.


1 Answers

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.

like image 122
Ereli Avatar answered Sep 25 '22 14:09

Ereli