How to turn a column of ints into one array in postgres

I currently have a table with one column and 400 rows; each row has an integer. How can I create an int array with all of these integers that preserves order?

I am using postgreSQL-9.2.


select array_agg(int_column order by some_column) as int_array_column
from the_table;

Where some_column is the column that defines the "order" of the integer values. Rows in relational database do not have "an order", so your request "that preserves order" only makes sense if you have a column that defines that sort order that you try to preserve.


SELECT array_agg(column_name ORDER by sort_column_name) AS ints
FROM table
链接地址: http://www.djcxy.com/p/87230.html

上一篇: PostgreSQL LIKE查询性能变化

下一篇: 如何在postgres中将一列ints变成一个数组