Solved

PostgreSQL, array value must start with '{'

Posted on 2008-09-30
2
1,141 Views
Last Modified: 2012-05-05
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
Comment
Question by:msosno
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
earth man2 earned 500 total points
ID: 22618503
testdb=> select ARRAY['0'] as content;
 content
---------
 {0}
(1 row)
0
 
LVL 22

Expert Comment

by:earth man2
ID: 22618566
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question