pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: deinspanjer@gmail.com
Subject: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset
Date: Sun, 25 Feb 2018 01:08:17 +0000
Message-ID: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15085
Logged by:          Daniel Einspanjer
Email address:      deinspanjer@gmail.com
PostgreSQL version: 9.6.7
Operating system:   Linux
Description:        

I was trying to create two domains, one that allowed nulls, and another that
built on it that didn't allow nulls.  After some testing, I came across this
unusual behavior that I believe might be a bug.
I did check the TODO and tried to do some web searches (hard keywords to
work with here) but I didn't find any reports about this.

Please find below a simple test case.

create domain test_domain text not null;
create temporary table
test_domain_constraint_vs_column_constraint(val_to_return test_domain,
val_to_find test_domain not null);
insert into test_domain_constraint_vs_column_constraint values
('good','good');
select * from test_domain_constraint_vs_column_constraint;
-- the domain constraint doesn't allow this insert.
insert into test_domain_constraint_vs_column_constraint values
(null,'bad');
-- the table constraint doesn't allow this insert.
insert into test_domain_constraint_vs_column_constraint values
('bad',null);

create function test_domain_constraint_in_return(_in test_domain) returns
test_domain language sql strict as $$
select val_to_return from test_domain_constraint_vs_column_constraint where
val_to_find = _in;
$$;

-- happy case
select test_domain_constraint_in_return('good') as val,
pg_typeof(test_domain_constraint_in_return('good')) as typ;

-- sad case
select test_domain_constraint_in_return('ugly') as val,
pg_typeof(test_domain_constraint_in_return('ugly')) as typ;

-- if we try to insert into the val_to_find column, the column constraint
prevents it
insert into test_domain_constraint_vs_column_constraint values
('ugly',test_domain_constraint_in_return('ugly'));

-- but if we insert into the val_to_return column which only has the domain
constraint to protect it, we succeed.
insert into test_domain_constraint_vs_column_constraint values
(test_domain_constraint_in_return('ugly'),'ugly');
select * from test_domain_constraint_vs_column_constraint where
val_to_return is null;

-- cleanup
drop domain test_domain cascade ;
drop table test_domain_constraint_vs_column_constraint;



view thread (5+ messages)  latest in thread

Message-ID: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org>
Permalink:  ../151952089752.1463.4091997216675283064@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/151952089752.1463.4091997216675283064@wrigleys.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, deinspanjer@gmail.com
  Subject: Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset
  In-Reply-To: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org>
  References: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org>

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

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