Re: BUG #1956: Plpgsql top-level DECLARE does not share scope - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1956: Plpgsql top-level DECLARE does not share scope
Date
Msg-id 23735.1129224656@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #1956: Plpgsql top-level DECLARE does not share scope  ("Jim C. Nasby" <jnasby@pervasive.com>)
Responses Re: BUG #1956: Plpgsql top-level DECLARE does not share scope
List pgsql-bugs
"Jim C. Nasby" <jnasby@pervasive.com> writes:
> Based on all that, I would certainly be in favor of throwing a warning
> if you over-define something, since 99% of the time it's a mistake. Is
> that possible with the current checking we do at compile time?

Without having looked at the code, I imagine the problem is that we
can't tell this situation from an ordinary nested DECLARE block,
that is

    declare x int;
    begin
        ...
        declare x float;
        begin
            ...

The above is legal code and I don't think we should throw a warning for
it.

Basically, DECLARE introduces a new name scope that wouldn't be there
if you didn't say DECLARE.  Without some bizarre reinterpretation of the
meaning of a DECLARE at the start of a function, variables automatically
created by plpgsql are going to be in an outer scope surrounding that of
the first DECLARE.

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: BUG #1956: Plpgsql top-level DECLARE does not share scope
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #1815: ECPGdebug causes crash on Windows XP