Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Text to an Array - PostgreSQL

im learning PostgreSQL and i encountered a little Problem.

I have a text like this:

'{1,1}'

and want to create an Array that holds my two values, so that i can access them. How do i do that ? I tried

SELECT string_to_array('{1,1}', '{', '}', ',');

But that does not seem to work.

like image 923
Tony Avatar asked Nov 17 '17 21:11

Tony


People also ask

What is Array_agg in Postgres?

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.

What is Unnest in PostgreSQL?

Unnest function generates a table structure of an array in PostgreSQL. Unnest array function is beneficial in PostgreSQL for expanding the array into the set of values or converting the array into the structure of the rows. PostgreSQL offers unnest() function.


1 Answers

'{1,1}' can be casted to an array directly:

select '{1,1}'::int[]
like image 90
a_horse_with_no_name Avatar answered Oct 03 '22 18:10

a_horse_with_no_name