Referencing uninitialized variables in plpgsql

From: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Referencing uninitialized variables in plpgsql
Date: 2005-02-06 04:20:51
Message-ID: 1107663651l.23980l.2l@mofo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I've a plpgsql procedure I'm pretty sure is referencing
variables, array elements really, that have not been
initialized. Is this a well defined operation?
If so, what is the result? (NULL?) If not, shouldn't I be
getting some sort of error or warning?

I've
SET client_min_messages='debug';
and don't seem to get any messages. AFICT there is no
run time configuration that would affect this, right?

The documentation seems silent on uninitialized plpgsql
variables. Be nice if something was written.

I don't care for code that references unititialized variables.
It'd be nice to be able to get a warning even if the result
was well defined, just for those cases where you don't intend
to reference uninitialized variables.

Is this example telling me I get NULL for unitialized references?
I don't believe I should count on this behavior unless it's
documented, should I?

=> create or replace function foo() returns int language plpgsql
as 'declare a int; b int; begin a := b; return a; end; ';
CREATE FUNCTION
=> select foo();
foo
-----

(1 row)

PostgreSQL 7.4.6 on i686-redhat-linux-gnu, compiled by GCC gcc
(GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-42)

Thanks for all the postgresql work. I don't mean to sound
grumpy, I'm tired.

Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karl O. Pinc 2005-02-06 04:30:49 Re: security
Previous Message Ron Peterson 2005-02-06 02:08:00 security