PL/pgSQL NOT NULL variables

From: Richard Poole <richard(dot)poole(at)vi(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: PL/pgSQL NOT NULL variables
Date: 2001-01-05 16:34:09
Message-ID: 20010105163409.C23742@office.vi.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-05 16:39:17 Re: select distinct null
Previous Message Scott Shealy 2001-01-05 16:30:56 ODBC failure