agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Julien Tachoires <julien.tachoires@dalibo.com>
To: pgsql-hackers@postgresql.org
Subject: Rowtype column and domain subfield with DEFAULT and NOT NULL constraint
Date: Wed, 12 Mar 2014 09:55:34 +0100
Message-ID: <53202106.3070207@dalibo.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (3+ messages)  latest in thread

Message-ID: <53202106.3070207@dalibo.com>
Permalink:  ../53202106.3070207@dalibo.com/
Also on:    postgresql.org/message-id/53202106.3070207@dalibo.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: julien.tachoires@dalibo.com
  Subject: Re: Rowtype column and domain subfield with DEFAULT and NOT NULL constraint
  In-Reply-To: <53202106.3070207@dalibo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox