1

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.

2 Answers 2

1
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.

Sign up to request clarification or add additional context in comments.

Comments

0
SELECT array_agg(column_name ORDER by sort_column_name) AS ints
FROM table

1 Comment

Code-only answers are discouraged, because they contain no searchable content. They also don't explain why they should "try this", and we make an effort here to be a resource for knowledge. Posting a block of code with no other information isn't sharing knowledge - it's just offering copy/paste code.

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.