From: | "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at> |
---|---|
To: | <dario(dot)ber(at)libero(dot)it>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: quote string exactly as it is |
Date: | 2009-12-02 15:17:03 |
Message-ID: | D960CB61B694CF459DCFB4B0128514C203938094@exadv11.host.magwien.gv.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Alexey Klyukin | 2009-12-02 15:18:51 | Re: Large Objects and Replication question |
Previous Message | Tom Lane | 2009-12-02 15:04:42 | Re: Roles with passwords; SET ROLE ... WITH PASSWORD ? |