Re: any way for ORDER BY x to imply NULLS FIRST in 8.3?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: rihad <rihad(at)mail(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: any way for ORDER BY x to imply NULLS FIRST in 8.3?
Date: 2007-11-06 14:48:37
Message-ID: 19134.1194360517@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

rihad <rihad(at)mail(dot)ru> writes:
> Is there any way to "hardcode" the NULL handling in an index (as per
> http://www.postgresql.org/docs/8.3/static/indexes-ordering.html) so that
> SELECT * FROM t ORDER BY foo automatically implies NULLS FIRST (and,
> similarly so that SELECT * FROM t ORDER BY foo DESC automatically
> implies NULLS LAST)?

No. This is not a question of how indexes behave, it is a question of
which semantics the parser ascribes to an undecorated ORDER BY request.

> Thing is, I'm using PHP Symfony/Propel to generate
> their SQL and have no easy way to influence how they do so.

SQL99 section 14.1 <declare cursor> saith:

... Whether
a sort key value that is null is considered greater or less
than a non-null value is implementation-defined, but all sort
key values that are null shall either be considered greater
than all non-null values or be considered less than all non-
null values. ...

Essentially the same text appears in SQL2003. Any application that
depends on one particular choice here is therefore broken, or at least
has chosen to work with only about half of the DBMSes in the world.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2007-11-06 14:53:12 Re: Selecting all but a few fields in a query
Previous Message SHARMILA JOTHIRAJAH 2007-11-06 14:37:46 Re: Postgresql simple query performance question