Re: Behaviour of rows containg not-null domains in plpgsql - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: Behaviour of rows containg not-null domains in plpgsql
Date
Msg-id 47C1A924.6000207@dunslane.net
Whole thread Raw
In response to Behaviour of rows containg not-null domains in plpgsql  ("Florian G. Pflug" <fgp@phlo.org>)
Responses Re: Behaviour of rows containg not-null domains in plpgsql
Re: Behaviour of rows containg not-null domains in plpgsql
List pgsql-hackers

Florian G. Pflug wrote:
> 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.
>
>

What seems worse is that it still fails even if you declare the domain 
to have a default value.

cheers

andrew


pgsql-hackers by date:

Previous
From: "Florian G. Pflug"
Date:
Subject: Behaviour of rows containg not-null domains in plpgsql
Next
From: Tom Lane
Date:
Subject: Re: 8.3 / 8.2.6 restore comparison