Re: Inserting string with a " into an array using {} syntax ... possible?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Bill Moran <wmoran(at)potentialtech(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Inserting string with a " into an array using {} syntax ... possible?
Date: 2009-03-13 13:41:43
Message-ID: 162867790903130641o2716d83x664964a7fac1d819@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

try
postgres=# SELECT ARRAY['text "for you" some'];
array
---------------------------
{"text \"for you\" some"}
(1 row)

regards
Pavel Stehule

2009/3/13 Bill Moran <wmoran(at)potentialtech(dot)com>:
>
> 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/
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message James B. Byrne 2009-03-13 13:46:12 Re: nulls
Previous Message Bill Moran 2009-03-13 13:21:10 Inserting string with a " into an array using {} syntax ... possible?