pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: listar <listar@mail.ru>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6155: literal definition of arrays with double qoutes leads to error
Date: Tue, 09 Aug 2011 01:02:20 -0400
Message-ID: <6103.1312866140@sss.pgh.pa.us> (raw)
In-Reply-To: <201108082022.p78KM2jZ050528@wwwmaster.postgresql.org>
References: <201108082022.p78KM2jZ050528@wwwmaster.postgresql.org>

"listar" <listar@mail.ru> writes:
> SELECT ('{string "with" double quotes}'::text[])[1] as value;
> gives:

> ERROR:  malformed array literal: "{string "with" double quotes}"
> LINE 1: SELECT ('{string "with" double quotes}'::text[])[1] as value...
>                 ^

This is not a bug; that value does not follow the documented rules for
array literals.  Per the manual:

As shown previously, when writing an array value you can use double
quotes around any individual array element. You must do so if the
element value would otherwise confuse the array-value parser. For
example, elements containing curly braces, commas (or the data type's
delimiter character), double quotes, backslashes, or leading or trailing
whitespace must be double-quoted. Empty strings and strings matching the
word NULL must be quoted, too. To put a double quote or backslash in a
quoted array element value, use escape string syntax and precede it with
a backslash. Alternatively, you can avoid quotes and use
backslash-escaping to protect all data characters that would otherwise
be taken as array syntax.


An example of correct format is

regression=# select E'{"string \\"with\\" double quotes"}'::text[];
               text                
-----------------------------------
 {"string \"with\" double quotes"}
(1 row)

Frequently it's easier to use an array[] constructor:

regression=# select array['string "with" double quotes'::text];
               array               
-----------------------------------
 {"string \"with\" double quotes"}
(1 row)

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <6103.1312866140@sss.pgh.pa.us>
Permalink:  ../6103.1312866140@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6103.1312866140@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, listar@mail.ru
  Subject: Re: BUG #6155: literal definition of arrays with double qoutes leads to error
  In-Reply-To: <6103.1312866140@sss.pgh.pa.us>
  References: <201108082022.p78KM2jZ050528@wwwmaster.postgresql.org> <6103.1312866140@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox