Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • Last Modified:

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?

0
msosno
Asked:
msosno
  • 2
1 Solution
 
earth man2Commented:
testdb=> select ARRAY['0'] as content;
 content
---------
 {0}
(1 row)
0
 
earth man2Commented:
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)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now