Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7AB56B5DBF1 for ; Tue, 9 Aug 2011 02:02:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 75349-01 for ; Tue, 9 Aug 2011 05:02:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 3D37DB5DBCB for ; Tue, 9 Aug 2011 02:02:24 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p7952Kf3006104; Tue, 9 Aug 2011 01:02:20 -0400 (EDT) To: "listar" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6155: literal definition of arrays with double qoutes leads to error In-reply-to: <201108082022.p78KM2jZ050528@wwwmaster.postgresql.org> References: <201108082022.p78KM2jZ050528@wwwmaster.postgresql.org> Comments: In-reply-to "listar" message dated "Mon, 08 Aug 2011 20:22:02 +0000" Date: Tue, 09 Aug 2011 01:02:20 -0400 Message-ID: <6103.1312866140@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.712 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.812 X-Spam-Level: X-Archive-Number: 201108/75 X-Sequence-Number: 30887 "listar" 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