Sorting by NULL values - Mailing list pgsql-sql

From Ian Burrell
Subject Sorting by NULL values
Date
Msg-id 3E65023E.10404@onsitetech.com
Whole thread Raw
Responses Re: Sorting by NULL values  (Dan Langille <dan@langille.org>)
Re: Sorting by NULL values  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Re: Sorting by NULL values  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
I am doing a query where I need to sort by a column that may be NULL 
because it is coming from an OUTER JOIN.  I noticed a difference between
PostgreSQL and other databases about where NULLs show up.  It seems that 
with Postgres, NULLs are sorted after other values.  Other databases 
sort them before.

Is there any standard on how sorting NULLs work?  Is there a way to 
change Postgres's behavior?  Is there a way to replace the NULLs with 
empty strings?

This is my query:

SELECT product_id
FROM product p
LEFT OUTER JOIN attribute_data ad
ON p.product_id= ad.product_id
AND ad.attribute_id = ?
WHERE p.category_id = ?
ORDER BY data;

The tables look like:

CREATE TABLE product (   product_id serial NOT NULL PRIMARY KEY,   category_id integer NOT NULL
);

CREATE TABLE attribute_data (   attribute_id integer NOT NULL,   product_id integer NOT NULL,   data varchar(1024),
PRIMARYKEY (attribute_id, product_id)
 
);
 - Ian



pgsql-sql by date:

Previous
From: Joe Conway
Date:
Subject: Re: Convert a text list to text array? Was: Denormalizing during
Next
From: Jean-Luc Lachance
Date:
Subject: Re: Forcing query to use an index