Re: When is a record NULL?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: Brendan Jurd <direvus(at)gmail(dot)com>, Jeff Davis <pgsql(at)j-davis(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: When is a record NULL?
Date: 2009-07-24 17:35:08
Message-ID: b42b73150907241035ja15c1c7v9ad90c29626ce352@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 24, 2009 at 5:15 AM, David E. Wheeler<david(at)kineticode(dot)com> wrote:
> On Jul 23, 2009, at 9:34 PM, Brendan Jurd wrote:
>
>> Well, a ROW is an ordered set of values, each one of which may be
>> either NULL or NOT NULL.
>
> Right.
>
>> It doesn't really make sense to talk about the ROW itself being NULL
>> or NOT NULL, only its member values (but for extra confusion, contrast
>> with the treatment of arrays, which can themselves be NULL).
>
> Well then maybe a record (row) should *never* be null.

I disagree, and I think our current way of treating things is
incorrect (although harmless). I rowtype can be null:

select null::somerowtype;

I think the following should _not_ return true:
select (null, null)::somerowtype is null;

The reasoning being that while the rowtype members are null, the
record variable itself is not; these are two distinct cases and should
be checked for and treated differently.

Another line of reasoning for this is that if something gives 'true'
for the is null operator, it should behave as null does, giving null
for any operations on it and giving null for STRICT functions, to give
a couple of examples.

create table foo (a int, b int);
select (null, null)::foo is null;
?column?
----------
t

create or replace function doit(foo) returns void as $$ begin raise
notice '!'; end; $$ language plpgsql strict;

select doit(row(null, null)::foo);
NOTICE: ! <-- what???!?

I think this is wrong, and if the sql standard sez it is so, then the
standard is wrong :-).

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2009-07-24 17:44:37 Re: When is a record NULL?
Previous Message Jeff Davis 2009-07-24 17:30:42 Re: WIP: Deferrable unique constraints