Re: pl/pgsql oddity - Mailing list pgsql-general

From Neil Conway
Subject Re: pl/pgsql oddity
Date
Msg-id 41C15E4C.4070500@samurai.com
Whole thread Raw
In response to Re: pl/pgsql oddity  (Richard Huxton <dev@archonet.com>)
Responses Re: pl/pgsql oddity  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Richard Huxton wrote:
> You want "elsif" - plpgsql isn't a hugely sophisticated language and its
> parser is having trouble there. I'm guessing the parser is somehow
> putting the "elseif" branch under the initial "then" so it never gets
> executed.

Indeed; the parser thinks an unrecognized keyword indicates the
beginning of a SQL statement: since the PL/PgSQL parser and the SQL
parser are completely separate, we need to do some guessing about what
constitutes a legal SQL statement. See the more detailed diagnose of the
problem here:

http://archives.postgresql.org/pgsql-bugs/2004-11/msg00297.php

There's a patch in that thread that provides better PL/PgSQL error
checking (which results in flagging this kind of code as invalid at
compile time). Some form of that patch will be in 8.1, as well as other
nice stuff like warning for unreachable code.

Tom also suggested just adding 'elseif' as an alternative for 'elsif'.
That sounds like it would be worth doing.

> Congratulations - I think you've found a bug. You can report it formally
> via the bugs mailing list

No need, this is a known issue.

-Neil

pgsql-general by date:

Previous
From: "Joolz"
Date:
Subject: Re: pl/pgsql oddity
Next
From: Richard Huxton
Date:
Subject: Re: pl/pgsql oddity