Re: Domain checks not always working when used in compound type

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Domain checks not always working when used in compound type
Дата
Msg-id 3236280.1703879366@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Domain checks not always working when used in compound type  (Holger Jakobs <holger@jakobs.com>)
Ответы Re: Domain checks not always working when used in compound type  (Holger Jakobs <holger@jakobs.com>)
Список pgsql-admin
Holger Jakobs <holger@jakobs.com> writes:
> -- Using the domain within a compound type. The NOT NULL constraint 
> should be
> -- inherited from the domain, therefore not repeated here for column a.
> CREATE TYPE compound_ab AS (
>    a    domain_a,
>    b    varchar(10)
> );

You are assuming in effect that a simple NULL value for a composite
type is the same thing as ROW(NULL, NULL).  They are not quite the
same, and one way in which they are not is that we don't consider
field-level constraints when deciding if a simple NULL value is legal
for the composite -- it always is.  Thus

regression=# select null::compound_ab;
 compound_ab 
-------------
 
(1 row)

regression=# select row(null, null)::compound_ab;
ERROR:  domain domain_a does not allow null values

The SQL spec itself is pretty schizophrenic about whether ROW(NULL, NULL)
is equivalent to bare NULL.  This is how we've chosen to interpret it.
I'll freely admit that there's some implementation considerations
involved in that choice, but we're unlikely to revisit it.

If you don't want things to work like this, you could attach a NOT
NULL constraint to the test1.ab column (as well as having the domain
constraint).

            regards, tom lane



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

Предыдущее
От: Holger Jakobs
Дата:
Сообщение: Domain checks not always working when used in compound type
Следующее
От: Holger Jakobs
Дата:
Сообщение: Re: Domain checks not always working when used in compound type