Problema con postgresql

giovedì 26 febbraio 2009 - 21.15

bryger Profilo | Newbie

Ciao a tutti,
ho un problema con l'uso del db in oggetto, spero che la sezone sia giusta.
Devo lanciare una query nella quale un campo di tipo testo contiene il carattere \, ora essendo usato come carattere di escape dal motore viene generato un errore percui vorrei sapere come fare per poterlo far diventare 'carattere normale', un po' come l'apice che viene raddoppiato per poterlo inserire nelle insert o update ; la query è di questo tipo :

insert into tabella values (1,25,' \ da importo', ecc....

Grazie

alx_81 Profilo | Guru

>Ciao a tutti,
Ciao!

>Devo lanciare una query nella quale un campo di tipo testo contiene
>il carattere \, ora essendo usato come carattere di escape dal
>motore viene generato un errore percui vorrei sapere come fare
>per poterlo far diventare 'carattere normale', un po' come l'apice
>che viene raddoppiato per poterlo inserire nelle insert o update
Hai provato a raddoppiare il carattere \?
tipo:
INSERT INTO tabella (campo1) VALUES ('prova \\ prova')

>Grazie
di nulla!
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org

bryger Profilo | Newbie

Sì, ma non funziona, il messaggio di errore è lo stesso......

alx_81 Profilo | Guru

lo scarico, provo e ti faccio sapere
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org

bryger Profilo | Newbie

Non importa ho risolto, il doppio \ va bene, mi dava solo un warning poi c'era un altro problema su una chiave ed era per quello che non inseriva.
Grazie

alx_81 Profilo | Guru

Ecco cosa dice la doc ufficiale:

"PostgreSQL also accepts “escape” string constants, which are an extension to the SQL standard. An
escape string constant is specified by writing the letter E (upper or lower case) just before the opening
single quote, e.g. E’foo’. (When continuing an escape string constant across lines, write E only before
the first opening quote.) Within an escape string, a backslash character (\) begins a C-like backslash
escape sequence, in which the combination of backslash and following character(s) represents a special
byte value. \b is a backspace, \f is a form feed, \n is a newline, \r is a carriage return, \t is a tab.
Also supported are \digits, where digits represents an octal byte value, and \xhexdigits, where
hexdigits represents a hexadecimal byte value. (It is your responsibility that the byte sequences you
create are valid characters in the server character set encoding.) Any other character following a backslash
is taken literally. Thus, to include a backslash character, write two backslashes (\\). Also, a single quote
can be included in an escape string by writing \’, in addition to the normal way of ”
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org

alx_81 Profilo | Guru

ok, accetta la risposta che chiudiamo il thread
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5