Re: When is a record NULL?

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

On Fri, Jul 24, 2009 at 4:29 PM, Greg Stark<gsstark(at)mit(dot)edu> wrote:
> On Fri, Jul 24, 2009 at 7:49 PM, Merlin Moncure<mmoncure(at)gmail(dot)com> wrote:
>> Still, why:
>>
>> *) is select null::foo is distinct from (null, null)::foo; true?
>> (null should not be distinct from null)
>>
>> *) does (null, null) allow STRICT functions to execute?
>>
>> *) is (null, null)::text not null?
>
> These are all good questions. Are you interested in checking what the
> spec says should happen in these cases?

I don't have a copy :-). (Am I being obtuse, and not noticing
something obvious?)

I think though that one of three cases is true:

*) postgresql is not treating (null, null) as null except in the case
where checked with 'is null'.
*) postgresql is following spec, which basically contradicts itself.
*) the behavior is undefined

If the first case is true (i bet it is), then many things we do with
composite types are wrong on some level, seriously in some cases. for
example:

select count(rowtype) from foo;
select distinct rowtype from foo;
select * from foo join bar using (rowtype);

can all give the wrong answer.

regardless, I think the sql standard definition of null for rowtypes
is lame -- the way null works for arrays is much better, in that the
elements inside the array an be null, independently can the array
itself.

I like the current behavior of composites (all composite fields being
null is a pretty rare case in practice), and would argue against
bringing the database closer to spec if it turns out that we are doing
it incorrectly.

merin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2009-07-24 21:28:10 contrib/xml2 pfree bug
Previous Message Robert Haas 2009-07-24 21:15:14 Re: explain refactoring v4