Sorting by NULL values

Поиск
Список
Период
Сортировка
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 по дате отправления:

Предыдущее
От: Joe Conway
Дата:
Сообщение: Re: Convert a text list to text array? Was: Denormalizing during
Следующее
От: Jean-Luc Lachance
Дата:
Сообщение: Re: Forcing query to use an index