The following bug has been logged on the website:
Bug reference: 11944
Logged by: Jasen Betts
Email address: jasen@treshna.com
PostgreSQL version: 9.1.13
Operating system: linux
Description:
this does work
create function fails( a int) returns int language plpgsql as $$ begin
if CASE when a = 1 then true else false END
then return 1; else return 0; end if ;
end $$;
parentheses can make it work.
create function fails_not( a int) returns int language plpgsql as $$ begin
if ( CASE when a = 1 then true else false END )
then return 1; else return 0; end if ;
end $$;
It seems to be the plpgsql parser not treating the CASE-END as atomic when
looking for the end of the IF xpression.