Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8D95E4766BF for ; Tue, 17 Sep 2002 18:24:02 -0400 (EDT) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by postgresql.org (Postfix) with ESMTP id B8A224765FD for ; Tue, 17 Sep 2002 18:23:48 -0400 (EDT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id g8HMLH227467; Tue, 17 Sep 2002 18:21:17 -0400 (EDT) From: Bruce Momjian Message-Id: <200209172221.g8HMLH227467@candle.pha.pa.us> Subject: Re: How to select and result row number?? In-Reply-To: <8957.1032300796@sss.pgh.pa.us> To: Tom Lane Date: Tue, 17 Sep 2002 18:21:17 -0400 (EDT) Cc: "Ross J. Reedstrom" , Roland Roberts , Yudie , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/199 X-Sequence-Number: 9476 Tom Lane wrote: > Bruce Momjian writes: > >>> select nextval('temp_counter'), * from (select .... order by ...); > >> > >> Approximately the same solution, but without saving the result in a temp > >> table. > > > I thought about doing it this way. However, a subselect as a > > pseudotable is not guaranteed to return the data in any specific order, > > so I don't think this method work work reliably. > > Say what? Given the ORDER BY in the subselect, it will. > > Of course, you can't do any grouping or other processing at the outer > level, but the example as given is just fine. When you specify a table in FROM, there is no ordering to the table. Is it guaranteed that a subquery in FROM _does_ have an ordering. Does ANSI say it has an ordering? What if the subquery is involved in a join? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073