Re: [HACKERS] NULL field records handling in order clause - Mailing list pgsql-hackers

From Sean Lyndersay
Subject Re: [HACKERS] NULL field records handling in order clause
Date
Msg-id 2984a9287699deec3fd3c80305dd5ced
Whole thread Raw
In response to [HACKERS] NULL field records handling in order clause  (Constantin Teodorescu <teo@flex.ro>)
List pgsql-hackers
On Sat, 14 Jun 1997, Thomas G. Lockhart wrote:

> Constantin Teodorescu wrote:
> > PostgreSQL 6.1 , Linux RedHat 4.2 Kernel 2.0.30
> > Selecting all records and ordering ascending and descending on a field :
> > template1=> select * from pers order by cod;
> > template1=> select * from pers order by cod desc;
> > ("cod" fields which are null _always_ show up at the end)
>
> This is an interesting feature. The reason for this behavior is that
> "null" fields should (I think) always return FALSE in comparisons, and
> the order-by is done using "<" or ">" operators. Remember, "null" is
> nothing, *not anything*, and hence is not comparable to anything which
> is not null. Even two null values should compare FALSE, I think.
>

absolutely correct: true != NULL; false != NULL; NULL != NULL;
I'm not sure whether its part of the standard but most databases implement
the 'is' keyword as in: ...where xyx is NULL or xyz is NOT NULL;

as for sort order, hmm. i would intuitively consider nulls to sort after
everything else, but i'm not sure what the standard says

sean

________________________________________________________________________
Sean Lyndersay                        Time is natures way of making sure
lynders@hcs.harvard.edu                 things don't happen all at once.
________________________________________________________________________
[finger for all other info]          http://www.hcs.harvard.edu/~lynders

------------------------------

pgsql-hackers by date:

Previous
From: "Thomas G. Lockhart"
Date:
Subject: Re: [HACKERS] NULL field records handling in order clause
Next
From: Sean Lyndersay
Date:
Subject: [HACKERS] Cast ptr to int