Re: Escaping literal strings in pg_8.4

From: Willy-Bas Loos <willybas(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Escaping literal strings in pg_8.4
Date: 2012-04-18 07:10:40
Message-ID: CAHnozTgYqNd1+xjsaX0Gn2j42QoihOiJCW2gBq=Bgn5DjavtqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

well, you have one single quote before the first backslash. so that's the
end of the quoted string. Then comes a backslash, which is bad syntax. So
it's the quote, not the backslash that causes the error.

maybe you mean this:
--
Vediamo se quest''altro \r\n lo riconosce come un a capo \r\n e questo
dovrebbe essere il nuovo rigo: ''bla bla bla''!
--
psql -c "insert into bibl_memos values(12000, E'`cat prova12000.memo`');"
INSERT 0 1
psql -c "select * from bibl_memos"
id | val
-------+---------------------------------------------------------
12000 | Vediamo se quest'altro \r +
| lo riconosce come un a capo \r +
| e questo dovrebbe essere il nuovo rigo: 'bla bla bla'!
(1 row)

It is kind of hard to get text like that into insert statements.
I would advise to use COPY. It takes TAB delimeted files, or CSV (e.g. from
a spreadsheet)

HTH, cheers,

WBL

On Thu, Apr 12, 2012 at 7:45 PM, Ennio-Sr <nasr(dot)laili(at)tin(dot)it> wrote:

> Hi all!
>
> [using postgresql_8.4 under debian/GNU-Linux 2.6.32]
>
> I'm trying to understand how the escape_string is supposed to work.
> After writing a file ('prova12000.memo') with this single line:
> -----
> Vediamo se quest''altro E'\r\n' lo riconosce come un a capo E'\r\n' e
> questo dovrebbe essere il nuovo rigo: ''bla bla bla''!
> -----
> entered the command:
>
> $ psql mydb -c "insert into bibl_memos values(12000, '`cat
> prova12000.memo`');"
>
> and got:
>
> ERROR: syntax error at or near "\"
> LINE 1: ...bl_memos values(12000, 'Vediamo se quest''altro E'\r\n' lo r...
> ^
> Both the lines 'escape_string_warning=on' and
> 'standard_conforming_strings=off' are commented out in postgresql.conf.
>
> Could somebody please explain what is going wrong?
>
> Thanks for your attention. Regards,
> ennio
> --
> [Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
> Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
> [Why use Win$ozz (I say) if ... "even a fool can do that. )=(
> Do something you aren't good at!" (as Henry Miller used to say) ]
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

--
"Patriotism is the conviction that your country is superior to all others
because you were born in it." -- George Bernard Shaw

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Willy-Bas Loos 2012-04-18 07:22:05 Re: PgOLEDB.dll
Previous Message Tom Lane 2012-04-17 19:18:53 Re: unique constraint