Bug #842: pgplsql: IF-THEN-ELSIF-ELSE acts different from IF-THEN-ELSE IF

Started by PostgreSQL Bugs Listover 23 years ago2 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

J�rn Cornelius Olsen (jco@cornelius-olsen.dk) reports a bug with a severity of 4
The lower the number the more severe it is.

Short Description
pgplsql: IF-THEN-ELSIF-ELSE acts different from IF-THEN-ELSE IF

Long Description
1) The 'boolean-expression' after 'ELSIF' always evaluates to FALSE. According to the manual IF-THEN-ELSIF-ELSE should be formally equivalent to IF-THEN-ELSE-IF-THEN, yet the example code below shows differently.

2) Also: There is no parse error if one omits 'THEN' after 'ELSIF boolean-expression' which leads me to believe that ELSIF has never been implemented. Yet there is not warning or error message nor any notices in the documentation.

Apart from the above: Thanks for a great SQL!

Sample Code
*** For the record ***
select version();
version
-------------------------------------------------------------
PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

*** Demonstration ***

create function demo1() returns integer as '

begin
if false then
return 1;
elsif true then
return 2;
else
return 3;
end if;
end;' language 'plpgsql';

select demo1();

demo1
-------
3
(1 row)

create function demo2() returns integer as '
begin
if false then
return 1;
else
if true then
return 2;
else
return 3;
end if;
end if;
end;' language 'plpgsql';

select demo2();

demo2
-------
2
(1 row)

No file was uploaded with this report

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #842: pgplsql: IF-THEN-ELSIF-ELSE acts different from IF-THEN-ELSE IF

pgsql-bugs@postgresql.org writes:

pgplsql: IF-THEN-ELSIF-ELSE acts different from IF-THEN-ELSE IF

PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.96

elsif was implemented in 7.2. I'm surprised you're not getting a syntax
error message; but in any case we are not revisiting 7.1 anymore...

regards, tom lane