"Jack Douglas" <jackpdouglas@gmail.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