Thread: Dollar quoting docs, round 1

Dollar quoting docs, round 1

From
David Fetter
Date:
Kind people,

Please find attached a diff to the SGML docs that attempts to go over
the new dollar quoting feature.

In eager anticipation of comments & feedback,
I remain,
Your Humble Servant,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Attachment

Re: Dollar quoting docs, round 1

From
Peter Eisentraut
Date:
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.


Re: Dollar quoting docs, round 1

From
David Fetter
Date:
On Wed, Apr 28, 2004 at 08:28:58AM +0200, 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.

Peter,

I'd be delighted to simplify some of the quotes.  They can't all be $$
because of the nesting, so that's out.  Also, I believe it is a good
idea to give some idea of what is going on with the tags, as I do with
similar structures in other languages.  For example, when I am writing
up a piece of SQL in perl or php, the tag looks like this:

$sql = <<SQL
...
SQL

$sql = <<<SQL
...
SQL;

Thanks as always for your prompt insights.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Re: Dollar quoting docs, round 1

From
Bruce Momjian
Date:
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.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Dollar quoting docs, round 1

From
Bruce Momjian
Date:
David Fetter wrote:
> On Wed, Apr 28, 2004 at 08:28:58AM +0200, 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.
>
> Peter,
>
> I'd be delighted to simplify some of the quotes.  They can't all be $$
> because of the nesting, so that's out.  Also, I believe it is a good
> idea to give some idea of what is going on with the tags, as I do with
> similar structures in other languages.  For example, when I am writing
> up a piece of SQL in perl or php, the tag looks like this:
>
> $sql = <<SQL
> ...
> SQL
>
> $sql = <<<SQL
> ...
> SQL;

Interesting, but I think most people like to use a tag that identifies
what is happening, rather than the content.  I think that's why <<END is
used frequently, so END appears as the end.  Seeing SQL alone on a line
seems strange.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Dollar quoting docs, round 1

From
Andrew Dunstan
Date:
Bruce Momjian wrote:

>David Fetter wrote:
>
>
>>On Wed, Apr 28, 2004 at 08:28:58AM +0200, 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.
>>>
>>>
>>Peter,
>>
>>I'd be delighted to simplify some of the quotes.  They can't all be $$
>>because of the nesting, so that's out.  Also, I believe it is a good
>>idea to give some idea of what is going on with the tags, as I do with
>>similar structures in other languages.  For example, when I am writing
>>up a piece of SQL in perl or php, the tag looks like this:
>>
>>$sql = <<SQL
>>...
>>SQL
>>
>>$sql = <<<SQL
>>...
>>SQL;
>>
>>
>
>Interesting, but I think most people like to use a tag that identifies
>what is happening, rather than the content.  I think that's why <<END is
>used frequently, so END appears as the end.  Seeing SQL alone on a line
>seems strange.
>
>
>

I typically combine these approaches, with a heredoc marker like EOSQL

cheers

andrew

Re: Dollar quoting docs, round 1

From
David Fetter
Date:
On Wed, Apr 28, 2004 at 12:30:06PM -0400, 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?

This is a design feature, as I understand it.

> And there is no way of escaping that, right?

Right.

> They have to choose a different quote characters sequence.

Yes.  Here is a short, but (IMHO) useful example.  Incidentally, I
have not yet found a way to get it working in versions prior to CVS
HEAD.

CREATE OR REPLACE FUNCTION has_bad_chars(TEXT) RETURNS BOOLEAN AS
$function$
BEGIN
    RETURN ($1 ~ $q$[\t\r\n\v|\\]$q$);
END;
$function$ LANGUAGE plpgsql;

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Re: Dollar quoting docs, round 1

From
Andrew Dunstan
Date:
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