X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8E3FB9FA1B0 for ; Sun, 7 May 2006 19:57:07 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 49301-04 for ; Sun, 7 May 2006 19:57:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id BF5699F9AFD for ; Sun, 7 May 2006 19:57:03 -0300 (ADT) Received: (qmail 21416 invoked from network); 8 May 2006 00:58:16 +0200 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 8 May 2006 00:58:16 +0200 To: "Ben K." , pgsql-sql@postgresql.org Subject: Re: Most efficient way to hard-sort records References: <445C5A94.4020907@startnet.cz> Message-ID: From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Mon, 08 May 2006 00:58:15 +0200 In-Reply-To: User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/79 X-Sequence-Number: 25110 > Another version along that line ? > > # create sequence counterseq start 1; > -- (set/reset whenever a counter is needed) > > # select main_table.*, nextval('counterseq') as position2 > into sorted_main_table > from main_table, keytable where main_table.id = > keytable.main_table_id > order by value; You could also use generate_series(), but I don't know if it can generate unbounded series...