Sorting by NULL values
От | Ian Burrell |
---|---|
Тема | Sorting by NULL values |
Дата | |
Msg-id | 3E65023E.10404@onsitetech.com обсуждение исходный текст |
Ответы |
Re: Sorting by NULL values
Re: Sorting by NULL values Re: Sorting by NULL values |
Список | 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 по дате отправления: