Rowtype column and domain subfield with DEFAULT and NOT NULL constraint - Mailing list pgsql-hackers

From Julien Tachoires
Subject Rowtype column and domain subfield with DEFAULT and NOT NULL constraint
Date
Msg-id 53202106.3070207@dalibo.com
Whole thread Raw
Responses Re: Rowtype column and domain subfield with DEFAULT and NOT NULL constraint
List pgsql-hackers
Hi,

A customer has reported us a strange behaviour regarding a rowtype 
column with a domain subfield:

test=# CREATE DOMAIN my_int_not_null_1 AS INTEGER DEFAULT 1 NOT NULL;
CREATE DOMAIN
test=# CREATE TYPE  my_int_rowtype AS (
test(#     f1 INTEGER,
test(#     f2 my_int_not_null_1
test(# );
CREATE TYPE
test=# CREATE TABLE test (id SERIAL, col1 my_int_rowtype);
CREATE TABLE
test=# INSERT INTO test (col1.f1) VALUES (1);
INSERT 0 1
test=# INSERT INTO test (id, col1.f1) VALUES (2, 1);
INSERT 0 1
test=# INSERT INTO test (col1) VALUES ((1,NULL));
ERROR:  domain my_int_not_null_1 does not allow null values
test=# SELECT * FROM test; id | col1
----+------  1 | (1,)  2 | (1,)
(2 rows)

It seems:

- the DEFAULT value (from the domain) is not inserted
- the NOT NULL constraint is no applied excepting if we set explicitly 
the value to NULL, looks like it is the same issue than before, when 
there is no DEFAULT the parser/rewriter should set the column/subfield 
to NULL.

Is build_column_default() the right place to handle that case ?

-- 
Julien Tachoires
http://dalibo.com - http://dalibo.org



pgsql-hackers by date:

Previous
From: Murtuza Mukadam
Date:
Subject: git-review: linking commits to review discussion in git
Next
From: "Tomas Vondra"
Date:
Subject: Re: jsonb and nested hstore