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

Re: PL/pgSQL RENAME functionality in TODOs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: imad <immaad(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/pgSQL RENAME functionality in TODOs
Date: 2007-02-01 00:28:25
Message-ID: (view raw or flat)
Lists: pgsql-hackers
imad <immaad(at)gmail(dot)com> writes:
> OK, so renaming does not work in the same block.
> You can rename a vairable in a nested block and thats why it works for OLD/NEW.

> BTW, what is the purpose behind it? Declaring a variable in a block
> and quickly renaming it does not make sense to me.

I agree it's pretty useless; but if we're gonna forbid it then we should
throw a more sensible error than "syntax error".

Actually, it seems to me that it works in the nested-block case only for
rather small values of "work":

regression=# create function foo() returns int as $$
regression$# declare
regression$# x int := 1;
regression$# begin
regression$#  x := 2;
regression$#  declare
regression$#   rename x to y;
regression$#  begin
regression$#    y := 3;
regression$#  end;
regression$#  return x;
regression$# end$$ language plpgsql;
regression=# select foo();
ERROR:  column "x" does not exist
CONTEXT:  PL/pgSQL function "foo" line 10 at return

Surely the variable's name should be x again after we're out of the
nested block?

			regards, tom lane

In response to


pgsql-hackers by date

Next:From: Florian G. PflugDate: 2007-02-01 01:46:00
Subject: Re: [GENERAL] 8.2.1 Compiling Error
Previous:From: eleinDate: 2007-01-31 23:24:24
Subject: Re: [GENERAL] 8.2.1 Compiling Error

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