Re: Bug with plpgsql handling of NULL argument of compound type

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Bug with plpgsql handling of NULL argument of compound type
Дата
Msg-id 15249.1469211237@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Bug with plpgsql handling of NULL argument of compound type  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Ответы Re: Bug with plpgsql handling of NULL argument of compound type  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Re: Bug with plpgsql handling of NULL argument of compound type  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-hackers
Jim Nasby <Jim.Nasby@BlueTreble.com> writes:
> CREATE DOMAIN text_not_null AS text NOT NULL;
> CREATE TYPE c AS( t text_not_null, i int );
> CREATE TABLE test_table( id serial, c c );
> CREATE OR REPLACE FUNCTION test_func(i test_table) RETURNS oid LANGUAGE 
> plpgsql AS $$
> BEGIN
> RETURN pg_typeof(i);
> END$$;
> SELECT test_func(NULL);
> ERROR:  domain text_not_null does not allow null values
> CONTEXT:  PL/pgSQL function test_func(test_table) while storing call 
> arguments into local variables

Arguably, that error is perfectly correct, not a bug.

There is a rather squishy question as to whether NULL::composite_type
should be semantically equivalent to ROW(NULL,NULL,...)::composite_type.
If it is, then the SELECT should have failed before even getting into the
plpgsql function, because ROW(NULL,NULL) is surely not a valid value of
type c.  The SQL standard seems to believe that these things *are*
equivalent (at least, that was how we read the spec for IS [NOT] NULL).
We're not very good at making them actually act alike, but if they do act
alike in plpgsql, it's hard to call that a bug.

> FWIW, the only reason I created 'text_not_null' in my real-word case is 
> because I have a compound type that I don't want to allow NULLS for some 
> of it's fields.

FWIW, there is a very good argument that any not-null restriction on a
datatype (as opposed to a stored column) is broken by design.  How do
you expect a LEFT JOIN to a table with such a column to work?  We
certainly are not going to enforce the not-nullness in that context,
and that leads to the thought that maybe we should just deny the validity
of such restrictions across the board.
        regards, tom lane



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

Предыдущее
От: Jeff Janes
Дата:
Сообщение: Re: fixes for the Danish locale
Следующее
От: Andres Freund
Дата:
Сообщение: Re: Rethinking TupleTableSlot deforming