quote string exactly as it is

Started by dario.ber@libero.itover 16 years ago5 messagesgeneral
Jump to latest
#1dario.ber@libero.it
dario.ber@libero.it

Hello,

How can I quote a string *exactly* as it is? I tried using
quote_literal() but it doesn't return what I need in some cases.

E.g.

If my
string is: ss\\\ss

And I do:

select quote_literal('ss\\\ss');

I get:

E'ss\\ss' <-- My string now has E'' added and one backslash has been removed!

What I want to do is to pass a string to a custom made function. Since the
string can contain various metacharcters I need some way to pass this string
exactly as it is.

(For those who might be interested, the strings I'm working
with are FASTQ quality scores)

I'm using Postgresql 8.3 on Windows XP

Thanks
a lot!

Dario

#2Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: dario.ber@libero.it (#1)
Re: quote string exactly as it is

On Wed, Dec 2, 2009 at 12:10 PM, dario.ber@libero.it <dario.ber@libero.it>wrote:

Hello,

How can I quote a string *exactly* as it is? I tried using
quote_literal() but it doesn't return what I need in some cases.

E.g.

If my
string is: ss\\\ss

And I do:

select quote_literal('ss\\\ss');

I get:

E'ss\\ss' <-- My string now has E'' added and one backslash has been
removed!

http://www.postgresql.org/docs/8.3/static/sql-syntax-lexical.html

That E tells postgres, that string is escaped.

--
GJ

#3Merlin Moncure
mmoncure@gmail.com
In reply to: dario.ber@libero.it (#1)
Re: quote string exactly as it is

On Wed, Dec 2, 2009 at 7:10 AM, dario.ber@libero.it <dario.ber@libero.it> wrote:

Hello,

How can I quote a string *exactly* as it is? I tried using
quote_literal() but it doesn't return what I need in some cases.

E.g.

If my
string is: ss\\\ss

dollar quote it:

select $abc$ss\\\ss$abc$;

merlin

#4Laurenz Albe
laurenz.albe@cybertec.at
In reply to: dario.ber@libero.it (#1)
Re: quote string exactly as it is

dario.ber wrote:

How can I quote a string *exactly* as it is? I tried using
quote_literal() but it doesn't return what I need in some cases.

E.g.

If my
string is: ss\\\ss

And I do:

select quote_literal('ss\\\ss');

I get:

E'ss\\ss' <-- My string now has E'' added and one backslash
has been removed!

What I want to do is to pass a string to a custom made function. Since the
string can contain various metacharcters I need some way to pass this string
exactly as it is.

If the backslashes are your only problem, set
standard_conforming_strings=on
(in postgresql.conf or in your session).

Then backslashes are treated as normal characters
(unless you prepend the string constant with E).

laurenz=> SET standard_conforming_strings=on;
SET
laurenz=> select quote_literal('ss\\\ss');
quote_literal
---------------
E'ss\\\\\\ss'
(1 row)

Yours,
Laurenz Albe

#5Bill Todd
pg@dbginc.com
In reply to: dario.ber@libero.it (#1)
Re: quote string exactly as it is

My solution was to set standard_conforming_strings = on in postgresql.conf.

Bill

dario.ber@libero.it wrote:

Show quoted text

Hello,

How can I quote a string *exactly* as it is? I tried using
quote_literal() but it doesn't return what I need in some cases.

E.g.

If my
string is: ss\\\ss

And I do:

select quote_literal('ss\\\ss');

I get:

E'ss\\ss' <-- My string now has E'' added and one backslash has been removed!

What I want to do is to pass a string to a custom made function. Since the
string can contain various metacharcters I need some way to pass this string
exactly as it is.

(For those who might be interested, the strings I'm working
with are FASTQ quality scores)

I'm using Postgresql 8.3 on Windows XP

Thanks
a lot!

Dario