Rowtype column and domain subfield with DEFAULT and NOT NULL constraint

From: Julien Tachoires <julien(dot)tachoires(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Rowtype column and domain subfield with DEFAULT and NOT NULL constraint
Date: 2014-03-12 08:55:34
Message-ID: 53202106.3070207@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message MauMau 2014-03-12 11:09:47 Re: [bug fix] pg_ctl always uses the same event source
Previous Message Heikki Linnakangas 2014-03-12 08:23:40 Re: Torn page hazard in ginRedoUpdateMetapage()