Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "deinspanjer(at)gmail(dot)com" <deinspanjer(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset
Date: 2018-02-25 03:35:06
Message-ID: 13059.1519529706@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Saturday, February 24, 2018, PG Bug reporting form <
> noreply(at)postgresql(dot)org> wrote:
>> After some testing, I came across this
>> unusual behavior that I believe might be a bug.

> This appears to fall within the exceptions for not null noted in the
> documentation for create domain.
> https://www.postgresql.org/docs/9.6/static/sql-createdomain.html

Yeah, the core issue here is that at no point does the query attempt to
convert a value of some other type to the domain type. Rather, the
appearance of the null result falls out of the semantics of a scalar
subquery that returns no rows. Like the case for a "not null" domain
column on the right side of a left join, this is a basic inconsistency
in the SQL language, and it's not clear that anyone would thank us for
throwing errors. (But they *would* complain if we slowed down these
fundamental operations to check for such cases :-(.)

I've occasionally wondered if we should force domain types that appear in
these contexts to decay to their base type, so as to avoid the situation
of returning a value that claims to be of a domain type but is actually
null. (That is, the reported output column type in an outer join or
whatever would be the base type not the domain type.) I'm doubtful
that any but pedants would find that to be an improvement, though; and
I've not come across anything in the SQL standard that suggests an
implementation should do that.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message 趙明春 2018-02-25 07:14:46 Re: BUG #15076: postmaster crashes unexpectedly when using up arrow key in psql command
Previous Message David G. Johnston 2018-02-25 02:11:40 Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset