Re: BUG #4908: escaping and dollar quotes: "ERROR: unterminated string"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jack Douglas" <jackpdouglas(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4908: escaping and dollar quotes: "ERROR: unterminated string"
Date: 2009-07-08 21:06:00
Message-ID: 10216.1247087160@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Jack Douglas" <jackpdouglas(at)gmail(dot)com> writes:
> Am I missing something obvious here - I understand from the documentation no
> escapes are counted in dollar quoted strings?

Yes, and yes.

> postgres=> create or replace function temp() returns text language plpgsql
> AS $$
> postgres$> begin
> postgres$> return '\';
> postgres$> end; $$;
> ERROR: unterminated string
> CONTEXT: compile of PL/pgSQL function "temp" near line 2

The function body contains
return '\';

and that string literal causes a syntax error when we come to parse the
RETURN statement. You could do
return '\\';
or
return $q$\$q$;
or
return $$\$$;
but the last requires using other $-delimiters around the function body.

Or you could turn on standard_conforming_strings if you'd prefer not to
deal with escapes.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2009-07-08 21:22:45 Re: BUG #4908: escaping and dollar quotes: "ERROR: unterminated string"
Previous Message Jack Douglas 2009-07-08 20:53:03 BUG #4908: escaping and dollar quotes: "ERROR: unterminated string"