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

plpgsql unreachable code (was BUG #1329: Bug in IF-ELSEIF-ELSE construct)

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rico Wind <rw(at)rico-wind(dot)dk>,pgsql-bugs(at)postgresql(dot)org
Subject: plpgsql unreachable code (was BUG #1329: Bug in IF-ELSEIF-ELSE construct)
Date: 2004-11-27 13:56:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugspgsql-patches
Neil Conway wrote:
> (BTW, another thing this example exposes is that we don't issue warnings 
> about trivially-dead-code, such as statements in a basic block that 
> follow a RETURN. This would probably be also worth doing.)

Attached is a patch that implements this. Specifically, if there are any 
statements in the same block that follow a RETURN, EXIT (without 
condition) or RAISE EXCEPTION statement, we issue a warning at CREATE 

create function exit_warn() returns int as $$
declare x int;
     x := 5;
         x := x + 1;
         x := x + 2;
     end loop;
     x := x + 3;
     return x;
end;$$ language 'plpgsql';
WARNING:  assignment is unreachable, due to exit near line 6
CONTEXT:  compile of PL/pgSQL function "exit_warn" near line 7

No warning is issued if check_function_bodies is false.

AFAICS there is no current infrastructure for walking a PL/PgSQL 
function's parse tree, so I did this manually (which is easy enough, of 
course). In the future it might be a good idea to refactor this to use 
something akin to the "walker" infrastructure in the backend (for one 
thing the PL/PgSQL function dumping code could use this as well).

(BTW this patch is intended for 8.1, of course.)


Attachment: plpgsql-unreachable-1.patch
Description: text/plain (10.8 KB)

In response to


pgsql-bugs by date

Next:From: Andrew - SupernewsDate: 2004-11-27 14:24:40
Subject: bug in information_schema?
Previous:From: Honza RamešDate: 2004-11-27 11:44:41
Subject: WinXP bug

pgsql-patches by date

Next:From: Tom LaneDate: 2004-11-27 17:43:53
Subject: Re: plpgsql unreachable code (was BUG #1329: Bug in IF-ELSEIF-ELSE construct)
Previous:From: Neil ConwayDate: 2004-11-27 06:17:40
Subject: Re: BUG #1329: Bug in IF-ELSEIF-ELSE construct

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