dbTalk Databases Forums  

Re: [BUGS] Minor irritant with comment parsing in a function (SQL)

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] Minor irritant with comment parsing in a function (SQL) in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Peter Eisentraut
 
Posts: n/a

Default Re: [BUGS] Minor irritant with comment parsing in a function (SQL) - 10-08-2003 , 02:59 PM






Richard Huxton writes:

Quote:
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. 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:

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'. Comments are also allowed between the
parts:

'foo'
-- abc
'bar'

Still equivalent to 'foobar'. 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.

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.

--
Peter Eisentraut peter_e (AT) gmx (DOT) net


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #2  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] Minor irritant with comment parsing in a function (SQL) - 10-08-2003 , 03:39 PM






On Wednesday 08 October 2003 20:56, Peter Eisentraut wrote:
Quote:
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 ;-)

Quote:
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...

Quote:
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]
Quote:
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).

Quote:
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

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Minor irritant with comment parsing in a function (SQL) - 10-08-2003 , 04:36 PM



Peter Eisentraut <peter_e (AT) gmx (DOT) net> writes:
Quote:
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.
I think the minimum-damage place to fix this is by requiring \n after
{comment} in the horiz_whitespace rule. As is, it's possible for
xqcat to match to a second quote that is in the body of a -- comment.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #4  
Old   
Peter Eisentraut
 
Posts: n/a

Default Re: [BUGS] Minor irritant with comment parsing in a function (SQL) - 10-08-2003 , 05:03 PM



Tom Lane writes:

Quote:
I think the minimum-damage place to fix this is by requiring \n after
{comment} in the horiz_whitespace rule. As is, it's possible for
xqcat to match to a second quote that is in the body of a -- comment.
You mean like this?

horiz_whitespace ({horiz_space}|{comment}{newline})
whitespace_with_newline ({horiz_whitespace}*{newline}{whitespace}*)

That doesn't work. The offending comment in the example is matched to
{whitespace} after {newline} in the second rule. The {horiz_whitespace}*
is matched to empty. We could do

special_whitespace ({space}+|{comment}{newline})
horiz_whitespace ({horiz_space}|{comment})
whitespace_with_newline ({horiz_whitespace}*{newline}{special_whitespace}* )

--
Peter Eisentraut peter_e (AT) gmx (DOT) net


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.