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@xxxxxxxx>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)