Re: Escaping \

From: Cedar Cox <cedarc(at)visionforisrael(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Martijn van Dijk <martijn(at)hardworks(dot)nl>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Escaping \
Date: 2001-03-29 16:48:30
Message-ID: Pine.LNX.4.21.0103291844030.21176-100000@nanu.visionforisrael.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> > I've a problem with escaping a \ in a string.
> >
> > When I enter the query:
> >
> > SELECT '''\\\''; I get the right result: '\'
> >
> > But when I try this in a Function:
> >
> > CREATE FUNCTION sp_tmp() RETURNS varchar(10)
> > AS '
> > SELECT ''\\\' AS RESULT'
> > LANGUAGE 'sql';
> >
> > I get the following Parse-erros:
> >
> > psql:tmp1:4: ERROR: Unterminated quoted string. I don't understand why,
> > when you leave the SELECT-statement out you get '''\\\'' and that is not
> > unterminated.
>
> Had something similar myself the other day. The reason is that you are
> already one deep in Postgres' string-parser, so you need something like:
>
> SELECT ''\\\\'' AS RESULT

Seems as if this would give \\

I think you need something like

SELECT ''''\\\'' AS RESULT

In other words, double all the single quotes. (This leads to all kinds of
fun stuff with 7.1 and code generating queries ;)

-Cedar

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2001-03-29 16:59:00 Re: Calling Java from psql (was Re: requesting help)
Previous Message Tom Lane 2001-03-29 16:43:43 Re: [SQL] inconsistent functionality with LIKE operator