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

From Richard Huxton
Subject Re: pl/pgsql oddity
Date
Msg-id 41C156DF.6090704@archonet.com
Whole thread Raw
In response to pl/pgsql oddity  ("Joolz" <joolz@arbodienst-limburg.nl>)
Responses Re: pl/pgsql oddity
Re: pl/pgsql oddity
List pgsql-general
Joolz wrote:
> Hello everyone,
>
> When writing some serverside code I ran into an oddity that I
> managed to boil down to this:

>   elseif l >= 38 then

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. If you rewrite the function like so:

create or replace function fubar() returns varchar as '
declare
   l integer;
begin
   l = 34;
   if l < 38 then
     raise notice ''< 38: %'',l;
   elseif l >= 38
     then raise notice ''>= 38: %'',l;
   else
     raise notice ''this is not possible: %'',l;
   end if;

   return 0;
end;'
language 'plpgsql';

Now, try different values for "l" and you'll see what is happening.
Congratulations - I think you've found a bug. You can report it formally
via the bugs mailing list or http://www.postgresql.org/bugform.html

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Michael Ben-Nes
Date:
Subject: online backup in critical systems
Next
From: Tomasz Myrta
Date:
Subject: Re: pl/pgsql oddity