X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3D8D84762D3 for ; Tue, 4 Mar 2003 14:45:10 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 85976-10 for ; Tue, 4 Mar 2003 14:45:09 -0500 (EST) Received: from otserver.onsitetech.com (unknown [66.239.248.99]) by postgresql.org (Postfix) with ESMTP id D231D4762E9 for ; Tue, 4 Mar 2003 14:45:07 -0500 (EST) Received: from onsitetech.com (unverified [66.89.133.75]) by otserver.onsitetech.com (Rockliffe SMTPRA 4.5.6) with ESMTP id for ; Tue, 4 Mar 2003 11:38:56 -0800 Message-ID: <3E65023E.10404@onsitetech.com> Date: Tue, 04 Mar 2003 11:45:02 -0800 From: Ian Burrell User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Sorting by NULL values Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/131 X-Sequence-Number: 12171 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), PRIMARY KEY (attribute_id, product_id) ); - Ian