From: | "Karl O(dot) Pinc" <kop(at)meme(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Referencing uninitialized variables in plpgsql |
Date: | 2005-02-06 18:18:54 |
Message-ID: | 1107713934l.31129l.1l@mofo |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 02/05/2005 10:57:45 PM, John DeSoi wrote:
>
> Yes, exactly. If you don't assign a value to a declared pspgsql
> variable, it
> is NULL.
Thanks, just what I needed.
> If you are concerned
> about this, then always assign a value when you declare it.
This does not really address my concern. See below.
> Also, you can specify NOT NULL in your declaration to ensure a
> runtime error
> is generated if the variable is null. See:
>
> http://www.postgresql.org/docs/8.0/interactive/plpgsql-declarations.html
I don't know why I sometimes can't find this stuff when I need it.
I kept scanning for 'variable'.
Some quibbles. (Where the devils lurk. ;)
AFICT, the docs arn't clear when it comes to referencing unitialized
array elements. I assume you get NULL values here as well even
though other array elements may have been given non-NULL values.
Can I count on this?
Initializing all varaibles, whether in declarations, automatically,
or by assignment, is not a substiute for throwing an exception at
runtime when an unitialized variable is referenced. When
a program is written so that varaibles are given values before
those values are expected to be used, and not given values otherwise,
then runtime exceptions thrown when unitialized variables are
referenced are alerts that the program is operating in an
unexpected manner. Initializing all variables regardless of
whether the initial values are expected to be used does nothing
more than assure these sorts of alerts will not be raised,
increasing the likelyhood that unexpected program behavior
will go unnoticed and uncorrected.
So, it would be cool of plpgsql declarations could declare
a variable NOT NULL without having to assign a default
value, and then raise an 'illegal NULL' exception should
the variable be referenced before a value is assigned to it.
This sounds like it could be complicated to impliment,
except that something similar must already be happening
with unitialized array elements to produce NULL values
when these are referenced.
Karl <kop(at)meme(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Browne | 2005-02-06 18:38:12 | Re: Update command too slow |
Previous Message | Tom Lane | 2005-02-06 18:18:25 | Re: Referencing uninitialized variables in plpgsql |