Re: Update with a Repeating Sequence - Mailing list pgsql-general

From Webb Sprague
Subject Re: Update with a Repeating Sequence
Date
Msg-id b11ea23c0810140927v275adfabtec759f4f94f8c3ba@mail.gmail.com
Whole thread Raw
In response to Re: Update with a Repeating Sequence  (Bill Thoen <bthoen@gisnet.com>)
Responses Re: Update with a Repeating Sequence  (Bill Thoen <bthoen@gisnet.com>)
List pgsql-general
Untested ideas (beware):

Use an insert trigger that:
    curr_seq := select max(seq) from foo where field_id = NEW.field_id
    if curr_seq is null then  NEW.seq := 0
    else NEW.seq  := curr_seq + 1

(You have to figure out how to build the trigger infrastructure...)

If you need to do it on a table that is already populated, let us know.

On Tue, Oct 14, 2008 at 9:21 AM, Bill Thoen <bthoen@gisnet.com> wrote:
> Grzegorz Jas'kiewicz wrote:
>>
>> alter table foo add newid sequencial;
>>
>> alter table foo drop field_id;
>>
>> alter table foo rename newid to field_id;
>>
> I can't do that; I need to preserve the field_id values.
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

pgsql-general by date:

Previous
From: "Grzegorz Jaśkiewicz"
Date:
Subject: Re: Update with a Repeating Sequence
Next
From: Steve Atkins
Date:
Subject: Re: Update with a Repeating Sequence