X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 334A447636C for ; Fri, 4 Apr 2003 20:58:36 -0500 (EST) Received: from smtp7.andrew.cmu.edu (SMTP7.andrew.cmu.edu [128.2.10.87]) by postgresql.org (Postfix) with ESMTP id 71181476372 for ; Fri, 4 Apr 2003 20:58:35 -0500 (EST) Received: from cmu.edu (AMEET2.RES.cmu.edu [128.2.161.217]) (user=amcauley mech=PLAIN (0 bits)) by smtp7.andrew.cmu.edu (8.12.9/8.12.3.Beta2) with ESMTP id h351wcrh004741 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NOT) for ; Fri, 4 Apr 2003 20:58:39 -0500 Date: Fri, 4 Apr 2003 20:58:38 -0500 Mime-Version: 1.0 (Apple Message framework v551) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: UNION and ORDER BY ... IS NULL ASC From: "A.M." To: pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: <1E4E6631-670A-11D7-89FA-0030657192DA@cmu.edu> X-Mailer: Apple Mail (2.551) X-Spam-Status: No, hits=-8.3 required=5.0 tests=BAYES_10,UPPERCASE_25_50,USER_AGENT_APPLEMAIL version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/75 X-Sequence-Number: 12776 PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled by GCC 2.95.3 I have come across some unexpected behavior while dealing with a UNION and ORDER BY. I'd like some advice. Here's a scenario where I want to order by null values: CREATE TABLE test(a int); SELECT a FROM test UNION SELECT a FROM test ORDER BY a IS NULL ASC; returns: ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of the result columns whereas: SELECT a FROM test UNION SELECT a FROM test ORDER BY a; works fine. The column name is the same in both queries, yet I get an error! Obviously, this is a gross oversimplification of what I want to do, but I couldn't get it working in this minimal case. I also tried using the column number, and that returns the same results as the name. What am I doing wrong? Thanks for any info. ><><><><><><><><>< AgentM agentm@cmu.edu