Re: Escaping literal strings in pg_8.4 - Mailing list pgsql-novice

From Willy-Bas Loos
Subject Re: Escaping literal strings in pg_8.4
Date
Msg-id CAHnozTgYqNd1+xjsaX0Gn2j42QoihOiJCW2gBq=Bgn5DjavtqA@mail.gmail.com
Whole thread Raw
In response to Escaping literal strings in pg_8.4  (Ennio-Sr <nasr.laili@tin.it>)
Responses Re: Escaping literal strings in pg_8.4  (ennio <eiannucci@tin.it>)
Re: Escaping literal strings in pg_8.4  (Ennio-Sr <nasr.laili@tin.it>)
List 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.laili@tin.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@postgresql.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

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: unique constraint
Next
From: Willy-Bas Loos
Date:
Subject: Re: PgOLEDB.dll