Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgjQT-0000T5-JA for pgsql-general@arkaria.postgresql.org; Sat, 21 Jul 2018 04:23:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fgjQP-0003CZ-Bg for pgsql-general@arkaria.postgresql.org; Sat, 21 Jul 2018 04:23:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgjQP-0003CR-3e for pgsql-general@lists.postgresql.org; Sat, 21 Jul 2018 04:23:21 +0000 Received: from mailout04.t-online.de ([194.25.134.18]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgjQN-0000Z2-2p for pgsql-general@lists.postgresql.org; Sat, 21 Jul 2018 04:23:20 +0000 Received: from fwd10.aul.t-online.de (fwd10.aul.t-online.de [172.20.26.152]) by mailout04.t-online.de (Postfix) with SMTP id D80D941BD392 for ; Sat, 21 Jul 2018 06:23:17 +0200 (CEST) Received: from musicman.homeip.net (TD4yNcZYQha1MP+AW3+vSYJk8o6Y60EZRY1DsHs-L+iZBtTm0Bn2H0P8ecRiiPdgus@[93.203.202.173]) by fwd10.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1fgjQC-1lCL9E0; Sat, 21 Jul 2018 06:23:08 +0200 Received: (qmail 19638 invoked by uid 1000); 21 Jul 2018 04:23:07 -0000 Date: 21 Jul 2018 04:23:07 -0000 Subject: Re: sql questions To: pgsql-general@lists.postgresql.org From: hamann.w@t-online.de Message-Id: X-Mailer: TkMail 4.0beta9 Content-type: text/plain; charset=utf-8 In-Reply-To: <20180720150753.817240u65vouisis@www.gelassene-pferde.biz> X-ID: TD4yNcZYQha1MP+AW3+vSYJk8o6Y60EZRY1DsHs-L+iZBtTm0Bn2H0P8ecRiiPdgus X-TOI-MSGID: 7ca03b78-2762-4a83-9c71-ec5a2af3e6cc List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >> Zitat von hamann.w@t-online.de: >> >> > a) I am running some select query >> > select ... order by .... >> > Now, I would like to preserver the ordering through further >> > processing by adding a sequence number >> > Of course I can do: >> > create temp sequence mseq; >> > select xx.*, nextval('mseq') as ord from (select ... order by ....) xx; >> > drop sequence mseq; >> > Is there a simpler way (avoiding the create/drop parts) >> >> Can't you just do the ordering at the end of the processing? Maybe you >> need to drag along the order by columns and just dump them at the very >> end if applicable. >> Hi, in this specific case every search result consists of a pair of related entries that are not close to each other in ordering. So I order by first entry and use the row number to keep the second entry next to the first one, BTW: the use case is scanning a database of people for duplicates. Whenever there are 3 or more components in a name, the split betwwen first and last name can be ambiguous, and so its is common to find both "Ludwig" "van Beethoven" and "Ludwig van" "Beethoven" Best regards WOlfgang