Lists: | pgsql-hackers |
---|
From: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
---|---|
To: | "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | dollar-quoting in psql and in general |
Date: | 2004-08-12 01:28:53 |
Message-ID: | 6.1.1.1.0.20040812112535.04968570@203.8.195.10 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
While trying to understand dollar-quoting, I found the following in psql:
select $a$ hello $a$;
behaves as expected, but psql does not like
select $a$ \ $a$;
or
select $a$ \\ $a$;
Should it? How should a dollar-quote handle:
$a$ \$a\$a $a$
?
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 03 5330 3172 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp.mit.edu:11371 |/
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
Cc: | "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 02:47:15 |
Message-ID: | 23348.1092278835@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> While trying to understand dollar-quoting, I found the following in psql:
> select $a$ hello $a$;
> behaves as expected, but psql does not like
> select $a$ \ $a$;
> or
> select $a$ \\ $a$;
Define "does not like". The behavior seems correct to me.
> Should it? How should a dollar-quote handle:
> $a$ \$a\$a $a$
The value of that is " \$a\$a ". Backslashes are not special inside
dollar quotes --- nor is anything else, except the matching close tag.
regards, tom lane
From: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:00:26 |
Message-ID: | 6.1.1.1.0.20040812125946.049cb410@203.8.195.10 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
At 12:47 PM 12/08/2004, Tom Lane wrote:
>Backslashes are not special inside
>dollar quotes --- nor is anything else, except the matching close tag
If they are not special, then shouldnt:
select $a$\$a$;
result in
?column?
\
rather than an error?
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 03 5330 3172 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp.mit.edu:11371 |/
From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:07:44 |
Message-ID: | 411ADF00.9000708@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Philip Warner wrote:
> While trying to understand dollar-quoting, I found the following in psql:
>
> select $a$ hello $a$;
>
> behaves as expected, but psql does not like
>
> select $a$ \ $a$;
> or
> select $a$ \\ $a$;
>
> Should it? How should a dollar-quote handle:
>
> $a$ \$a\$a $a$
>
> ?
>
>
andrew=# select $a$ \ $a$;
?column?
----------
\
(1 row)
andrew=# select $a$ \\ $a$;
?column?
----------
\\
(1 row)
It is behaving as *I* expect, and as designed. \ is not magical inside
dollar quotes, and if it were it would defeat the whole purpose of
having them.
Dollar quotes are really designed for strings that are reparsed - most
typically function bodies. The strings inside them are therefore totally
opaque, and there is no escape character. Otherwise, if we wanted the
plpgsql parsers, say, to see \ we'd have to write \\, and the idea was
to get away from \\, \', '' and friends.
cheers
andrew
From: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
---|---|
To: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:21:06 |
Message-ID: | 6.1.1.1.0.20040812131702.04980be0@203.8.195.10 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
At 01:07 PM 12/08/2004, Andrew Dunstan wrote:
>\ is not magical inside dollar quotes,
Sorry, I was confused by the manual: the paragraph that starts "C-style
backslash escapes are also available..." is right after the paragraphs on
dollar-quoting.
The section on dollar-quoting is also not explicit about valid tags, "zero
or more characters" is all I can see. Can you give me a definitive answer
as to what is valid? AFAICT, must be [A-Z,a-z,0-9,_]*, with non-numeric
start. Is that right?
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 03 5330 3172 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp.mit.edu:11371 |/
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
Cc: | "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:27:49 |
Message-ID: | 23795.1092281269@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> At 12:47 PM 12/08/2004, Tom Lane wrote:
>> Backslashes are not special inside
>> dollar quotes --- nor is anything else, except the matching close tag
> If they are not special, then shouldnt:
> select $a$\$a$;
> result in
> ?column?
> \
> rather than an error?
Worksforme (TM).
regression=# select $a$\$a$;
?column?
----------
\
(1 row)
regression=#
Are you sure your psql and backend are both current?
regards, tom lane
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:49:59 |
Message-ID: | 24039.1092282599@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> At 01:07 PM 12/08/2004, Andrew Dunstan wrote:
>> \ is not magical inside dollar quotes,
> Sorry, I was confused by the manual: the paragraph that starts "C-style
> backslash escapes are also available..." is right after the paragraphs on
> dollar-quoting.
The documentation for dollar-quoting is pretty awful at the moment, as
it seems to have been pasted in with no thought to context, and is
incomplete anyway. I have on my to-do list to go over it, but if
someone else beats me to it I won't pout.
> The section on dollar-quoting is also not explicit about valid tags, "zero
> or more characters" is all I can see.
Use the source, Luke ... scan.l explains
/* $foo$ style quotes ("dollar quoting")
* The quoted string starts with $foo$ where "foo" is an optional string
* in the form of an identifier, except that it may not contain "$",
* and extends to the first occurrence of an identical string.
* There is *no* processing of the quoted text.
*/
dolq_start [A-Za-z\200-\377_]
dolq_cont [A-Za-z\200-\377_0-9]
dolqdelim \$({dolq_start}{dolq_cont}*)?\$
regards, tom lane
From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Philip Warner <pjw(at)rhyme(dot)com(dot)au> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: dollar-quoting in psql and in general |
Date: | 2004-08-12 03:53:12 |
Message-ID: | 411AE9A8.4000402@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Philip Warner wrote:
> At 01:07 PM 12/08/2004, Andrew Dunstan wrote:
>
>> \ is not magical inside dollar quotes,
>
>
> Sorry, I was confused by the manual: the paragraph that starts
> "C-style backslash escapes are also available..." is right after the
> paragraphs on dollar-quoting.
>
> The section on dollar-quoting is also not explicit about valid tags,
> "zero or more characters" is all I can see. Can you give me a
> definitive answer as to what is valid? AFAICT, must be
> [A-Z,a-z,0-9,_]*, with non-numeric start. Is that right?
>
>
Don't forget the high-bit chars too. pgsqlscan.l says:
dolq_start [A-Za-z\200-\377_]
dolq_cont [A-Za-z\200-\377_0-9]
dolqdelim \$({dolq_start}{dolq_cont}*)?\$
The scanner files for plpgsql and the backend have equivalent specs, so
this is definitive.
cheers
andrew