pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Escaping \
4+ messages / 4 participants
[nested] [flat]

* Escaping \
@ 2001-03-29 08:05  Martijn van Dijk <martijn@hardworks.nl>
  0 siblings, 2 replies; 4+ messages in thread

From: Martijn van Dijk @ 2001-03-29 08:05 UTC (permalink / raw)
  To: pgsql-sql

Hello all,

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.

Please help

Greetings

Martijn van Dijk







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Escaping \
@ 2001-03-29 12:35  Richard Huxton <dev@archonet.com>
  parent: Martijn van Dijk <martijn@hardworks.nl>
  1 sibling, 1 reply; 4+ messages in thread

From: Richard Huxton @ 2001-03-29 12:35 UTC (permalink / raw)
  To: Martijn van Dijk <martijn@hardworks.nl>; pgsql-sql

From: "Martijn van Dijk" <martijn@hardworks.nl>

> 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

HTH

- Richard Huxton




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Escaping \
@ 2001-03-29 16:05  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Martijn van Dijk <martijn@hardworks.nl>
  1 sibling, 0 replies; 4+ messages in thread

From: Tom Lane @ 2001-03-29 16:05 UTC (permalink / raw)
  To: Martijn van Dijk <martijn@hardworks.nl>; +Cc: pgsql-sql

"Martijn van Dijk" <martijn@hardworks.nl> writes:
> 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:

You need an extra level of quoting because the function body is itself
a string literal.  You might find the quoting discussion in
http://www.postgresql.org/devel-corner/docs/postgres/plpgsql-porting.html
helpful.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Escaping \
@ 2001-03-29 16:48  Cedar Cox <cedarc@visionforisrael.com>
  parent: Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Cedar Cox @ 2001-03-29 16:48 UTC (permalink / raw)
  To: Richard Huxton <dev@archonet.com>; +Cc: Martijn van Dijk <martijn@hardworks.nl>; 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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-03-29 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-29 08:05 Escaping \ Martijn van Dijk <martijn@hardworks.nl>
2001-03-29 12:35 ` Richard Huxton <dev@archonet.com>
2001-03-29 16:48   ` Cedar Cox <cedarc@visionforisrael.com>
2001-03-29 16:05 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox