Re: Referencing uninitialized variables in plpgsql

Поиск
Список
Период
Сортировка
От Karl O. Pinc
Тема Re: Referencing uninitialized variables in plpgsql
Дата
Msg-id 1107713934l.31129l.1l@mofo
обсуждение исходный текст
Ответ на Referencing uninitialized variables in plpgsql  ("Karl O. Pinc" <kop@meme.com>)
Ответы Re: Referencing uninitialized variables in plpgsql  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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@meme.com>
Free Software:  "You don't pay back, you pay forward."
                -- Robert A. Heinlein






В списке pgsql-general по дате отправления:

Предыдущее
От: "J. Greenlees"
Дата:
Сообщение: Re: [pgsql-advocacy] MySQL worm attacks Windows servers
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Referencing uninitialized variables in plpgsql