Skip site navigation (1) Skip section navigation (2)

Re: BUG #1329: Bug in IF-ELSEIF-ELSE construct

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Rico Wind <rw(at)rico-wind(dot)dk>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1329: Bug in IF-ELSEIF-ELSE construct
Date: 2004-11-29 16:59:28
Message-ID: 19420.1101747568@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-patches
Neil Conway <neilc(at)samurai(dot)com> writes:
> (2) The syntax error message is wrong (we print a character offset and
> query context that is relative to the CREATE FUNCTION statement, not the
> individual SQL statement we're executing). I fooled around a bit with
> defining a custom ereport() callback to print the right line number and
> query context, but I couldn't get it right. Do you have any guidance on
> the proper way to do this.

Hmm ... I was about to say the SQL function validator already does this
(see sql_function_parse_error_callback in pg_proc.c), but it has the
advantage that there's a one-to-one correspondence between the string it
sends to the main parser and a substring of the original function text.
In plpgsql that's not true because of (a) substitution of parameter
symbols for names and (b) the liberties that the plpgsql lexer takes
with whitespace and eliding comments.

You might be best off just to strive for output like this:

	ERROR: syntax error at or near...
	QUERY: select ...
	CONTEXT: compile of plpgsql function "frob" at SQL statement line 12

which ought to be relatively easy to get.

BTW, don't forget to check SQL expressions (eg, the condition of an IF)
as well as SQL statements.  In the case of EXECUTE, you can check
the expression that gives rise to the text string.

>> The error would be more useful if reported immediately
>> after the putative SQL statement is parsed.  Not sure if that's
>> hard or not.  (The same remark applies to dead code checking, now
>> that I think about it.)

> In the case of dead code checking, I don't think it matters.

My thought was that a dead-code error could well indicate a problem
along the lines of a missing begin or end, and that flagging the
dead-code error would probably provide a much closer pointer to the
true problem than barfing at the end of the input when we realize
we have unmatched begin/end structure.  (Especially since the barf
will likely take the form of a nonspecific "syntax error" message.
Anytime you can do better than that, you're ahead.)  Similarly, checking
expressions immediately will help report mismatched-parenthesis problems
in a more useful way than we do now.

			regards, tom lane

In response to

pgsql-bugs by date

Next:From: Luciano - UNILOG SADate: 2004-11-29 17:08:06
Subject: PLTCL
Previous:From: Tom LaneDate: 2004-11-29 16:27:14
Subject: Re: BUG #1331: after update: vacuum blocks parallel to select

pgsql-patches by date

Next:From: Tom LaneDate: 2004-11-30 00:14:01
Subject: Preliminary patch for on-the-fly relpages/reltuples estimation
Previous:From: Tom LaneDate: 2004-11-29 15:42:29
Subject: Re: multiline CSV fields

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group