Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D5624127D32C for ; Wed, 16 Nov 2011 11:19:46 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 51233-01 for ; Wed, 16 Nov 2011 15:19:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 99C17127D32B for ; Wed, 16 Nov 2011 11:19:40 -0400 (AST) Received: from [76.14.161.106] (helo=newserver.jfcomputer.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQhGz-0001Wa-Bq for pgsql-sql@postgresql.org; Wed, 16 Nov 2011 15:19:39 +0000 Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 4AAFE5846; Wed, 16 Nov 2011 15:19:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eJZHK29Hl8Rx; Wed, 16 Nov 2011 07:19:22 -0800 (PST) Received: from linux-desktop.localnet (unknown [192.168.1.143]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id E5C8A5759; Wed, 16 Nov 2011 07:19:21 -0800 (PST) From: John Fabiani Organization: J.F. Computer Solutions To: pgsql-sql@postgresql.org Subject: Re: updating a sequence Date: Wed, 16 Nov 2011 07:19:21 -0800 User-Agent: KMail/1.13.5 (Linux/2.6.34.10-0.2-desktop; KDE/4.4.4; i686; ; ) Cc: Scott Marlowe References: <201111150806.30911.johnf@jfcomputer.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201111160719.21111.johnf@jfcomputer.com> X-Host-Lookup-Failed: Reverse DNS lookup failed for 76.14.161.106 (failed) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/69 X-Sequence-Number: 36042 On Tuesday, November 15, 2011 07:46:19 pm Scott Marlowe wrote: > On Tue, Nov 15, 2011 at 5:33 PM, Samuel Gendler > > wrote: > > On Tue, Nov 15, 2011 at 4:28 PM, John Fabiani wrote: > >> On Tuesday, November 15, 2011 08:33:54 am Richard Broersma wrote: > >> > On Tue, Nov 15, 2011 at 8:06 AM, John Fabiani > >> > > >> > wrote: > >> > > alter sequence somename restart with (select max(pk) from > >> > > sometable). > >> > > > >> > > I need this for automating an ETL (using pentaho). > >> > > >> > http://www.postgresql.org/docs/9.1/interactive/functions-sequence.html > >> > #FUNC TIONS-SEQUENCE-TABLE > >> > >> I don't see how that helps answer my problem. I know how to update a > >> sequence. I want to pass a value for the restart vaue that depends on a > >> query > >> - all in one statement. I would think it is a common problem i.e. > >> migrating > >> data. > > > > use a subquery to set the value - > > select setval('foo', select max(some_id) from some_table) > > It's all right there in the docs that you were pointed to. We try to > > encourage people to be somewhat self sufficient around here. > > You need to wrap a subselect in (): > > select setval('foo', (select max(some_id) from some_table)); > > That works in 9.1.1. No clue about previous versions off the top of > my head, but I seem to recall it doesn't work in 8.3 and prior > versions. Thanks that did work with the parens. I could not get to work earlier. Johnf