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

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Minor irritant with comment parsing in a function (SQL)
Date: 2003-10-08 19:56:44
Message-ID: Pine.LNX.4.44.0310082147360.26413-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Richard Huxton 2003-10-08 20:34:38 Re: Minor irritant with comment parsing in a function (SQL)
Previous Message Hiroshi Saito 2003-10-08 18:32:49 Re: [BUGS] Degrade(character conversion problem) pga3?