X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E85AA529D0 for ; Tue, 28 Jun 2005 12:42:45 -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 57362-04 for ; Tue, 28 Jun 2005 15:42:44 +0000 (GMT) Received: from colo.samason.me.uk (unknown [69.55.228.22]) by svr1.postgresql.org (Postfix) with ESMTP id 7522A529E2 for ; Tue, 28 Jun 2005 12:42:43 -0300 (ADT) Received: from colo.samason.me.uk (colo [69.55.228.22]) by colo.samason.me.uk (8.12.11/8.12.11) with ESMTP id j5SFgh6O075550 for ; Tue, 28 Jun 2005 16:42:43 +0100 (BST) (envelope-from sam@colo.samason.me.uk) Received: (from sam@localhost) by colo.samason.me.uk (8.12.11/8.12.11/Submit) id j5SFgh1f075544 for pgsql-performance@postgresql.org; Tue, 28 Jun 2005 16:42:43 +0100 (BST) (envelope-from sam) Date: Tue, 28 Jun 2005 16:42:42 +0100 From: Sam Mason To: pgsql-performance@postgresql.org Subject: Re: tricky query Message-ID: <20050628154242.GS62747@colo.samason.me.uk> Mail-Followup-To: Sam Mason , pgsql-performance@postgresql.org References: <6EE64EF3AB31D5448D0007DD34EEB3415C2BEC@Herge.rcsinc.local> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3415C2BEC@Herge.rcsinc.local> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/557 X-Sequence-Number: 13194 Merlin Moncure wrote: >I've already worked out a query using generate_series (not scalable) and >pl/pgsql. An SQL only solution would be preferred, am I missing >something obvious? I would be tempted to join the table to itself like: SELECT id+1 FROM foo WHERE id > 0 AND i NOT IN (SELECT id-1 FROM foo) LIMIT 1; Seems to work for me. Not sure if that's good enough for you, but it may help. Sam