PL/pgSQL NOT NULL variables - Mailing list pgsql-general

From Richard Poole
Subject PL/pgSQL NOT NULL variables
Date
Msg-id 20010105163409.C23742@office.vi.net
Whole thread Raw
Responses Re: PL/pgSQL NOT NULL variables
Re: PL/pgSQL NOT NULL variables
List pgsql-general
This is my first attempt at using PL/pgSQL so I may be carrying around
a grotesque misconception of some sort...

I can't get NOT NULL variables to work at all in PL/pgSQL. Here's a
simple function which uses a default value for a variable:

test=> create function t1() returns integer as '
test'> declare foo integer := 42;
test'> begin return foo; end;
test'> ' language 'plpgsql';
CREATE
test=> select t1();
 t1
----
 42
(1 row)


No problem at all. But if I create a function exactly identical except
for making the variable NOT NULL:

test=> create function t2() returns integer as '
test'> declare foo integer not null := 42;
test'> begin return foo; end;
test'> ' language 'plpgsql';
CREATE
test=> select t2();
ERROR:  NULL assignment to variable 'foo' declared NOT NULL

I've tried using DEFAULT instead of :=, which the docs suggest should
be equivalent, and the same thing happens. Similarly when I use type
"text". As there are no NOT NULL variables in the examples or the
regression tests, I suspect I may have found a bug. Does anybody have
NOT NULL working in a PL/pgSQL function? Can anybody shed any light
on what I may be doing wrong?

7.02 on Debian GNU/Linux, FWIW.

Richard

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] Re: pg_dump return status..
Next
From: Scott Shealy
Date:
Subject: ODBC failure