Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Artacus
Bill Thoen wrote: Steve Atkins wrote: On Oct 14, 2008, at 9:04 AM, Bill Thoen wrote: I've got a table with repeated records that I want to make unique by adding a sequence code of 0,1,2,...,n for each set of repeated records. Basically, I want to turn: field_id | seq --+-

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Bill Thoen
Steve Atkins wrote: On Oct 14, 2008, at 9:04 AM, Bill Thoen wrote: I've got a table with repeated records that I want to make unique by adding a sequence code of 0,1,2,...,n for each set of repeated records. Basically, I want to turn: field_id | seq --+- 1 | 0 2 |

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Steve Atkins
On Oct 14, 2008, at 11:36 AM, Bill Thoen wrote: The table exists already; all I need to do is update the sequence code to make the records unique, but also I need each repeating set numbered from 0 (Zero) so I can select a list of unique farm field records where seq = 0. "select distinct

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Bill Thoen
The table exists already; all I need to do is update the sequence code to make the records unique, but also I need each repeating set numbered from 0 (Zero) so I can select a list of unique farm field records where seq = 0. I think that the suggestion to use a cursor sounds good, but I'm conc

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Steve Atkins
On Oct 14, 2008, at 9:04 AM, Bill Thoen wrote: I've got a table with repeated records that I want to make unique by adding a sequence code of 0,1,2,...,n for each set of repeated records. Basically, I want to turn: field_id | seq --+- 1 | 0 2 | 0 3 | 0

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Webb Sprague
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 t

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Grzegorz Jaśkiewicz
I would probably do that in plpgsql, as a cursor

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Bill Thoen
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 s

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Grzegorz Jaśkiewicz
oh, sorry - you want something else. blah.

Re: [GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Grzegorz Jaśkiewicz
alter table foo add newid sequencial; alter table foo drop field_id; alter table foo rename newid to field_id;

[GENERAL] Update with a Repeating Sequence

2008-10-14 Thread Bill Thoen
I've got a table with repeated records that I want to make unique by adding a sequence code of 0,1,2,...,n for each set of repeated records. Basically, I want to turn: field_id | seq --+- 1 | 0 2 | 0 3 | 0 3 | 0 3 | 0 4 | 0