Minor irritant with comment parsing in a function (SQL) body

From: Richard Huxton <dev(at)archonet(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Minor irritant with comment parsing in a function (SQL) body
Date: 2003-10-08 18:21:51
Message-ID: 200310081921.51688.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Versions: 7.3, 7.4beta (not latest)
Applies to SQL functions, but not apparently to plpgsql (because of the
different parser, I presume).

This is really a "doctor it hurts when I..." thing - the fact that I've never
come across it before must mean it's pretty hard to trigger.

The first version of this function compiles fine, the second doesn't.

CREATE OR REPLACE FUNCTION zzz_test () RETURNS text AS '
SELECT ''hello world''::text;
-- SELECT ''goodbye world''
' LANGUAGE 'SQL';

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;
"

It took forever to find a simple reproducible example, but the rules seem to
be:
1. You must have quoting at the end of both adjacent lines
2. Both lines must be within a single SQL statement.
3. You must use the -- comment, not /* ... */

Originally spotted with a formulation like:
AND type1 = ''A''
AND type2 = ''B''
...
I commented one test and got an error message.

--
Richard Huxton
Archonet Ltd

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Hiroshi Saito 2003-10-08 18:32:49 Re: [BUGS] Degrade(character conversion problem) pga3?
Previous Message Andreas Pflug 2003-10-08 17:48:18 Re: Degrade(character conversion problem) pga3?