Inserting string with a " into an array using {} syntax ... possible? - Mailing list pgsql-general

From Bill Moran
Subject Inserting string with a " into an array using {} syntax ... possible?
Date
Msg-id 20090313092110.da3178be.wmoran@potentialtech.com
Whole thread Raw
Responses Re: Inserting string with a " into an array using {} syntax ... possible?  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Inserting string with a " into an array using {} syntax ... possible?  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general
Between google searches and my own experiments, I can't find any way to
actually make this work.

I have a TEXT[] column, and one of the values I want to insert is
'text "for" you'.

Is there no way to do this using the {} syntax?  Chronicled below are
several of my attempts (various noise has been snipped):

bill=# create table testarray (a TEXT[], id BIGSERIAL PRIMARY KEY);

bill=# insert into testarray (a) values (E'{"text \"for you\"","moretext"}');
ERROR:  malformed array literal: "{"text "for you"","moretext"}"

bill=# insert into testarray (a) values (E'{"text \\"for you\\"","moretext"}');
INSERT 0 1
bill=# select * from testarray;
               a               | id
-------------------------------+----
 {"text \"for you\"",moretext} |  3

bill=# insert into testarray (a) values (E'{"text \"for you\"","moretext"}');
ERROR:  malformed array literal: "{"text "for you"","moretext"}"

bill=# insert into testarray (a) values (E'{"text ""for you","moretext"}');
ERROR:  malformed array literal: "{"text ""for you","moretext"}"
bill=# insert into testarray (a) values (E'{"text "for" you","moretext"}');
ERROR:  malformed array literal: "{"text "for" you","moretext"}"

bill=# insert into testarray (a) values (E'{"text \"for\" you","moretext"}');
ERROR:  malformed array literal: "{"text "for" you","moretext"}"

bill=# insert into testarray (a) values (E'{"text \042for\042 you","moretext"}');
ERROR:  malformed array literal: "{"text "for" you","moretext"}"

bill=# insert into testarray (a) values (E'{"text \\042for\\042 you","moretext"}');
INSERT 0 1
bill=# select * from testarray;
                a                | id
---------------------------------+----
 {"text 042for042 you",moretext} |  4


--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

pgsql-general by date:

Previous
From: Simon Riggs
Date:
Subject: Re: I don't want to back up index files
Next
From: Pavel Stehule
Date:
Subject: Re: Inserting string with a " into an array using {} syntax ... possible?