Link to home
Start Free TrialLog in
Avatar of msosno
msosno

asked on

PostgreSQL, array value must start with '{'

I need to execute the following PostgreSQL statement:
   select ('{'0'}'::varchar[]) as "content", .......
The column content is of type array. It does not exist in this particular table and needs to be initialized.

In the beginning I was getting  "array value must start with '{' ". Then I added curly braces and tried experimenting, but it still does not work. How can the query be fixed?

ASKER CERTIFIED SOLUTION
Avatar of earth man2
earth man2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
your curly brackets did not work because you terminate the array constant with the second apostrophe ie before the 0.  Use double quotes within the curly bracket

select x.content[2] from (select '{"0","21","32"}'::text[] as content) as x;
 content
---------
 21
(1 row)