Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D6BAF1BCFA82 for ; Wed, 16 Nov 2011 01:35:44 -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 87926-07 for ; Wed, 16 Nov 2011 05:35:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4BB2D1BCFA83 for ; Wed, 16 Nov 2011 01:35:37 -0400 (AST) Received: from mail-gx0-f174.google.com ([209.85.161.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQY9k-0001fG-6o for pgsql-sql@postgresql.org; Wed, 16 Nov 2011 05:35:36 +0000 Received: by ggnb2 with SMTP id b2so8336661ggn.19 for ; Tue, 15 Nov 2011 21:35:19 -0800 (PST) Received: by 10.50.194.229 with SMTP id hz5mr31357195igc.36.1321418375623; Tue, 15 Nov 2011 20:39:35 -0800 (PST) Received: from [10.50.184.11] ([166.205.141.44]) by mx.google.com with ESMTPS id a2sm21628270igj.7.2011.11.15.20.39.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Nov 2011 20:39:34 -0800 (PST) References: <201111150806.30911.johnf@jfcomputer.com> <201111151628.23731.johnf@jfcomputer.com> In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: <8B98F15B-E050-43B6-8784-36FD3E8570B2@ideasculptor.com> Cc: John Fabiani , "pgsql-sql@postgresql.org" , RichardBroersma X-Mailer: iPhone Mail (9A334) From: Sam Gendler Subject: Re: updating a sequence Date: Tue, 15 Nov 2011 20:39:29 -0800 To: Scott Marlowe 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/67 X-Sequence-Number: 36040 Sent from my iPhone On Nov 15, 2011, at 7:49 PM, Scott Marlowe wrote: > On Tue, Nov 15, 2011 at 8:46 PM, Scott Marlowe w= rote: >> On Tue, Nov 15, 2011 at 5:33 PM, Samuel Gendler >> wrote: >>> On Tue, Nov 15, 2011 at 4:28 PM, John Fabiani wro= te: >>>>=20 >>>> 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).= >>>>>>=20 >>>>>> I need this for automating an ETL (using pentaho). >>>>>=20 >>>>>=20 >>>>> http://www.postgresql.org/docs/9.1/interactive/functions-sequence.html= #FUNC >>>>> TIONS-SEQUENCE-TABLE >>>>=20 >>>>=20 >>>> 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. >>>>=20 >>>=20 >>> use a subquery to set the value - >>> select setval('foo', select max(some_id) from some_table) >>> It's all right there in the with docs that you were pointed to. We try t= o >>> encourage people to be somewhat self sufficient around here. >>=20 >> You need to wrap a subselect in (): >>=20 >> select setval('foo', (select max(some_id) from some_table)); >>=20 >> 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. >=20 > Was wrong, it definitely works in 8.3. But only with the parens. Yes. My version without parens was just a typo. I didn't test it before send= ing it=