From: Sam Gendler <sgendler@ideasculptor.com>
To: Scott Marlowe <scott.marlowe@gmail.com>
Cc: John Fabiani <johnf@jfcomputer.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Cc: RichardBroersma <richard.broersma@gmail.com>
Subject: Re: updating a sequence
Date: Tue, 15 Nov 2011 20:39:29 -0800
Message-ID: <8B98F15B-E050-43B6-8784-36FD3E8570B2@ideasculptor.com> (raw)
In-Reply-To: <CAOR=d=1OAyExiv=T2txJX4HTgDLGYS4qE6puBbt_EOqO5Di2Uw@mail.gmail.com>
References: <201111150806.30911.johnf@jfcomputer.com>
<CABvLTWGNa470FXAR=zXu_PeFJ9GtQ-MPAcDfq=Bq7vPVuF2drA@mail.gmail.com>
<201111151628.23731.johnf@jfcomputer.com>
<CAEV0TzApAcAtTZYqHGGexBfvps__v9oTwEQ5dGrtEqHPEYeW3w@mail.gmail.com>
<CAOR=d=3fahvFCn80mQLwK4Pnru7u1DiV5ZTD3oyxe7S+sSpXjA@mail.gmail.com>
<CAOR=d=1OAyExiv=T2txJX4HTgDLGYS4qE6puBbt_EOqO5Di2Uw@mail.gmail.com>
Sent from my iPhone
On Nov 15, 2011, at 7:49 PM, Scott Marlowe <scott.marlowe@gmail.com> wrote:
> On Tue, Nov 15, 2011 at 8:46 PM, Scott Marlowe <scott.marlowe@gmail.com> wrote:
>> On Tue, Nov 15, 2011 at 5:33 PM, Samuel Gendler
>> <sgendler@ideasculptor.com> wrote:
>>> On Tue, Nov 15, 2011 at 4:28 PM, John Fabiani <johnf@jfcomputer.com> wrote:
>>>>
>>>> On Tuesday, November 15, 2011 08:33:54 am Richard Broersma wrote:
>>>>> On Tue, Nov 15, 2011 at 8:06 AM, John Fabiani <johnf@jfcomputer.com>
>>>>> 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 with 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.
>
> 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 sending it
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sgendler@ideasculptor.com, scott.marlowe@gmail.com, johnf@jfcomputer.com, richard.broersma@gmail.com
Subject: Re: updating a sequence
In-Reply-To: <8B98F15B-E050-43B6-8784-36FD3E8570B2@ideasculptor.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox