X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 88DCC475C3D for ; Fri, 4 Apr 2003 23:17:38 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id BD5D4475A45 for ; Fri, 4 Apr 2003 23:17:37 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h354He2L011806; Fri, 4 Apr 2003 23:17:41 -0500 (EST) To: josh@agliodbs.com Cc: "A.M." , pgsql-sql@postgresql.org Subject: Re: UNION and ORDER BY ... IS NULL ASC In-reply-to: <200304041852.30121.josh@agliodbs.com> References: <1E4E6631-670A-11D7-89FA-0030657192DA@cmu.edu> <200304041852.30121.josh@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Fri, 04 Apr 2003 18:52:30 -0800" Date: Fri, 04 Apr 2003 23:17:40 -0500 Message-ID: <11805.1049516260@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/78 X-Sequence-Number: 12779 Josh Berkus writes: >> ERROR: ORDER BY on a UNION/INTERSECT/EXCEPT result must be on one of >> the result columns > I do believe that this is per the SQL spec; UNIONs may only be sorted on the > output columns. Right. We extend the SQL spec for ORDER BY on simple selects, but we have not gotten around to doing so for ORDER BY on set-operation results. You can only sort by unadorned output columns. Patches to improve this are welcome ;-) regards, tom lane