Skip site navigation (1) Skip section navigation (2)

Behaviour of rows containg not-null domains in plpgsql

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Postgresql-Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Behaviour of rows containg not-null domains in plpgsql
Date: 2008-02-24 16:49:02
Message-ID: 47C19FFE.1030507@phlo.org (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi

I just stumbled over the following behaviour, introduced with 8.3, and
wondered if this is by design or an oversight.

If you define a domain over some existing type, constrain it to
non-null values, and use that domain as a field type in a table 
definition, it seems to be impossible to declare pl/pgsql variables
of that table's row type. The problem seems to be that upon declaration,
the row variable is filled with nulls - but since the domain is marked
not-null, that immediatly triggers an exception.

Here is an example
CREATE DOMAIN d AS varchar NOT NULL;
CREATE TABLE t (txt d);
CREATE FUNCTION f() RETURNS VOID AS $$
DECLARE
   v_t t;
BEGIN
END;
$$ LANGUAGE 'plpgsql' VOLATILE;
SELECT f();

Note that the following works.
CREATE TABLE t2 (txt varchar not null);
CREATE FUNCTION f2() RETURNS VOID AS $$
DECLARE
   v_t t2;
BEGIN
END;
$$ LANGUAGE 'plpgsql' VOLATILE;
SELECT f2();

If you guys agree that this is a bug, I'll try to find a fix and send a 
patch.

greetings, Florian Pflug


Responses

pgsql-hackers by date

Next:From: Pavel StehuleDate: 2008-02-24 16:54:13
Subject: idea: simple variadic functions in SQL and PL/pgSQL
Previous:From: andyDate: 2008-02-24 14:21:18
Subject: Re: 8.3 / 8.2.6 restore comparison

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group