pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: mailreg@numerixtechnology.de
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY and NULLs
Date: 19 Sep 2004 14:37:11 -0400
Message-ID: <87zn3mjeaw.fsf@stark.xeocode.com> (raw)
In-Reply-To: <414DBF6D.8040500@numerixtechnology.de>
References: <011d01c49e5b$c88fdb20$2766f30a@development.greatgulfhomes.com>
	<414DB1AB.5080207@sympatico.ca>
	<414DB594.5000300@numerixtechnology.de>
	<19733.1095613137@sss.pgh.pa.us>
	<414DBF6D.8040500@numerixtechnology.de>


T E Schmitz <mailreg@numerixtechnology.de> writes:

> I just dug out the PostgreSQL book again because I thought I might've garbled
> it:
> 
> Quote: "PostgreSQL will not index NULL values. Because an index will never
> include NULL values, it cannot be used to satisfy the ORDER BY clause of a
> query that returns all rows in a table."

You should just cross out that whole section. It's just flatly wrong. 

I had always assumed it was just people bringing assumptions over from Oracle
where it is true. Perhaps this book is to blame for some of the confusion.
Which book is it?

Postgres indexes NULLs. It can use them for ORDER BY clauses. 

Where it cannot use them is to satisfy "WHERE foo IS NULL" or "WHERE foo IS
NOT NULL" constraints though. That's an implementation detail, but it can be
worked around with partial indexes.

-- 
greg




view thread (16+ messages)  latest in thread

Message-ID: <87zn3mjeaw.fsf@stark.xeocode.com>
Permalink:  ../87zn3mjeaw.fsf@stark.xeocode.com/
Also on:    postgresql.org/message-id/87zn3mjeaw.fsf@stark.xeocode.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gsstark@mit.edu, mailreg@numerixtechnology.de, tgl@sss.pgh.pa.us
  Subject: Re: ORDER BY and NULLs
  In-Reply-To: <87zn3mjeaw.fsf@stark.xeocode.com>

* 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