From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: deinspanjer@gmail.com <deinspanjer@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset
Date: Sat, 24 Feb 2018 22:35:06 -0500
Message-ID: <13059.1519529706@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYhRsU_Qw4ird9YwgjQNxxX4+1Z0YDbRRGH_CENmOBDfg@mail.gmail.com>
References: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org>
<CAKFQuwYhRsU_Qw4ird9YwgjQNxxX4+1Z0YDbRRGH_CENmOBDfg@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Saturday, February 24, 2018, PG Bug reporting form <
> noreply@postgresql.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
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: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, deinspanjer@gmail.com
Subject: Re: BUG #15085: Domain "not null" constraint doesn't detect a null returned from a resultset
In-Reply-To: <13059.1519529706@sss.pgh.pa.us>
References: <151952089752.1463.4091997216675283064@wrigleys.postgresql.org> <CAKFQuwYhRsU_Qw4ird9YwgjQNxxX4+1Z0YDbRRGH_CENmOBDfg@mail.gmail.com> <13059.1519529706@sss.pgh.pa.us>
* 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