Re: Dollar quoting docs, round 1 - Mailing list pgsql-patches

From Andrew Dunstan
Subject Re: Dollar quoting docs, round 1
Date
Msg-id 408FE41B.1060503@dunslane.net
Whole thread Raw
In response to Re: Dollar quoting docs, round 1  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-patches
Bruce Momjian wrote:

>Peter Eisentraut wrote:
>
>
>>David Fetter wrote:
>>
>>
>>>Kind people,
>>>
>>>Please find attached a diff to the SGML docs that attempts to go over
>>>the new dollar quoting feature.
>>>
>>>
>>I think we should just use $$ in each case.  Otherwise it might look
>>more complicated than before.
>>
>>
>
>Agreed.  I was worried about dollar arguments in functions, e.g. $1:
>
>    test=> select $$$1$$;
>     ?column?
>    ----------
>     $1
>    (1 row)
>
>but that seems to be OK.  Is our only problem actual $$ in a function
>body?  And there is no way of escaping that, right?  They have to choose
>a different quote characters sequence.
>
>
>

The string inside $x$ is totally opaque and unescaped. The restriction
on markers is that the string mustn't contain $x$, and mustn't end with
$x, i.e., the scanners see $x$ and simply accumulate all the characters
in the string until they see $x$ again - all 3 scanners (postgres, psql,
plpgsql) work the same way on this.

Functions with arguments might need to be quoted with something other
than plain $$, and in any case if their bodies make use of $$ they
certainly will. pg_dump's approach to quoting function bodies is to
start with $$ and then generate longer and longer markers until the
marker without trailing $ is not found in the string comprising the
function body. In most cases it ends up using $_$.

I hope that makes things clearer.

cheers

andrew


pgsql-patches by date:

Previous
From: David Fetter
Date:
Subject: Re: Dollar quoting docs, round 1
Next
From: Sean Chittenden
Date:
Subject: Re: SECURITY DEFINER not being propagated...