X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1AE345295A for ; Wed, 29 Jun 2005 11:23:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 66744-08 for ; Wed, 29 Jun 2005 14:23:20 +0000 (GMT) Received: from hotmail.com (bay103-f2.bay103.hotmail.com [65.54.174.12]) by svr1.postgresql.org (Postfix) with ESMTP id 524C452968 for ; Wed, 29 Jun 2005 11:23:19 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 29 Jun 2005 07:22:07 -0700 Message-ID: Received: from 65.54.174.206 by by103fd.bay103.hotmail.msn.com with HTTP; Wed, 29 Jun 2005 14:22:07 GMT X-Originating-IP: [65.54.174.206] X-Originating-Email: [russellsimpkins@hotmail.com] X-Sender: russellsimpkins@hotmail.com In-Reply-To: <20050629115723.GA31013@winnie.fuhr.org> From: "Russell Simpkins" To: mike@fuhr.org Cc: pgsql-sql@postgresql.org Subject: Re: ORDER records based on parameters in IN clause Date: Wed, 29 Jun 2005 10:22:07 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 29 Jun 2005 14:22:07.0731 (UTC) FILETIME=[EE351C30:01C57CB5] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.354 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: * X-Archive-Number: 200506/358 X-Sequence-Number: 21959 fair enough. but a simple order by id would never work. >From: Michael Fuhr >To: Russell Simpkins >CC: pgsql-sql@postgresql.org >Subject: Re: [SQL] ORDER records based on parameters in IN clause >Date: Wed, 29 Jun 2005 05:57:23 -0600 > >On Wed, Jun 29, 2005 at 07:19:22AM -0400, Russell Simpkins wrote: > > > > Order by id will not do what you want, but this should. > > Select * from table where id = 2003; > > Union all > > Select * from table where id = 1342; > > Union all > > Select * from table where id = 799; > > Union all > > Select * from table where id = 1450; > >Note that the semicolons should be omitted everywhere except for >at the end of the entire query. Also, although the implementation >might happen to return rows in that order, the documentation states >that it's not guaranteed to: > >http://www.postgresql.org/docs/8.0/static/queries-union.html > >"UNION effectively appends the result of query2 to the result of >query1 (although there is no guarantee that this is the order in >which the rows are actually returned)." > >As the documentation states elsewhere and as the SQL standard says, >without ORDER BY rows are returned in an unspecified order. The >above query works by accident, not by design, so although it might >work today there's no guarantee that it'll work tomorrow. > >-- >Michael Fuhr >http://www.fuhr.org/~mfuhr/ > >---------------------------(end of broadcast)--------------------------- >TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)