From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: Minor irritant with comment parsing in a function (SQL) |
Date: | 2003-10-08 20:34:38 |
Message-ID: | 200310082134.38535.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Wednesday 08 October 2003 20:56, Peter Eisentraut wrote:
> Richard Huxton writes:
> > CREATE OR REPLACE FUNCTION zzz_test () RETURNS text AS '
> > SELECT ''hello world''
> > -- SELECT ''goodbye world''
> >
> > ::text;
> >
> > ' LANGUAGE 'SQL';
> >
> > ERROR: parser: unterminated quoted string at or near "'hello world'
> > -- SELECT 'goodbye world'
> >
> > ::text;
>
> That's a good one.
Well, I try ;-)
> The bug is actually independent of the function
> definition, but you cannot easily reproduce it in psql, because psql cuts
> out -- comment before sending the command to the server. Here's how one
> could do it:
You intrigue me sir...
> cmd=$(echo -e "SELECT 'hello world'\n-- SELECT 'goodbye world'\n::text;")
> psql -c "$cmd"
>
> The problem is strings of this form:
>
> 'foo'
> 'bar'
>
> This is equivalent to 'foobar'.
Ah - now if I ever new that, I'd forgotten it.
[snip]
> In your case it's scanning the string
> similar to
>
> 'hello world'
> -- SELECT 'goodbye world
> '\n::text;
>
> Hence the complain the the string is not terminated.
So given the "comment" defn in scan.l, it's seeing the quote as the next token
in the input stream? (Wracks brain thinking back to compiler technologies
class in a decade a long, long way from here).
> The bug here is that the scanner doesn't know that a newline (or end of
> input) is a required as part of a -- comment. If I change the rule
>
> comment ("--"{non_newline}*)
>
> in scan.l to
>
> comment ("--"{non_newline}*){newline}
>
> then the example works. This does not cover the case of a comment at the
> end of the input, but a solution shall be forthcoming.
Ah - in perl you'd be looking for a pattern anchored with a $ - I see what you
mean.
Thanks for the explanation Peter.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2003-10-08 20:36:14 | Re: pg_resetxlog and pgscripts italian translation |
Previous Message | Peter Eisentraut | 2003-10-08 19:56:44 | Re: Minor irritant with comment parsing in a function (SQL) |