Re: [SQL] Increment a sequence by more than one

2007-08-06 Thread Steve Midgley
Hi Peter, I struggled to implement Michael's suggestion to use CACHE in this regard when he made it but after your encouragement I've studied it more and you and he are both totally right - CACHE is designed to do exactly what I want. Here's the sample code so as to put this issue to bed and

Re: [SQL] Increment a sequence by more than one

2007-08-06 Thread Peter Childs
On 03/08/07, Michael Glaesemann <[EMAIL PROTECTED]> wrote: > > > On Aug 3, 2007, at 15:27 , Erik Jones wrote: > > > Is there actually a requirement that the block of 5000 values not > > have gaps? > > Good point. > > > If not, why not make the versioned table's id column default to > > nextval from

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
On Aug 3, 2007, at 15:27 , Erik Jones wrote: Is there actually a requirement that the block of 5000 values not have gaps? Good point. If not, why not make the versioned table's id column default to nextval from the same sequence? Of course, the ids of the two tables could be interleaved

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
On Aug 3, 2007, at 14:28 , Steve Midgley wrote: AIUI, one difference between the solutions Scott and I proposed is that while INCREMENT is set at 5000, each time nextval is called the sequence is incremented by 5000. For example: test=# select nextval('foos_foo_id_seq'); nextval -

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Erik Jones
On Aug 3, 2007, at 11:50 AM, Steve Midgley wrote: Hi, I'm writing an import app in a third party language. It's going to use "copy to" to move data from STDIN to a postgres (8.2) table. There are some complexities though: it's going to copy the records to a "versioned" table first, and th

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Scott Marlowe
Oh, another point. You should run the alter sequence m increment 5000; select nextval('m'); alter sequence m increment 1; one right after the other to reduce the number of 5000 wide holes in your sequence. Or, given the size of bigint, you could just set the increment to 5000 and leave it there

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Scott Marlowe
On 8/3/07, Steve Midgley <[EMAIL PROTECTED]> wrote: > Hi Scott, > > Thanks for this info (and Michael too!). > > Let me see if I understand your suggestion. I would run these three > commands in sequence: > > # select nextval('[my_seq_name]'); > returns => 52 [I believe that the sequence is at 52]

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Steve Midgley
Hi Scott, Thanks for this info (and Michael too!). Let me see if I understand your suggestion. I would run these three commands in sequence: # select nextval('[my_seq_name]'); returns => 52 [I believe that the sequence is at 52] # alter sequence [my_seq_name] increment by 5000; # select nextv

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Scott Marlowe
On 8/3/07, Steve Midgley <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm writing an import app in a third party language. It's going to use > "copy to" to move data from STDIN to a postgres (8.2) table. There are some > complexities though: it's going to copy the records to a "versioned" table > first

Re: [SQL] Increment a sequence by more than one

2007-08-03 Thread Michael Glaesemann
On Aug 3, 2007, at 11:50 , Steve Midgley wrote: My problem: I'd like to be able to grab a block of id's from the live table's pk sequence. So let's say my importer has 5,000 new rows to import and the current max pk in the live table is 540,203. I'd like to be able to increment the primary

[SQL] Increment a sequence by more than one

2007-08-03 Thread Steve Midgley
Hi, I'm writing an import app in a third party language. It's going to use "copy to" to move data from STDIN to a postgres (8.2) table. There are some complexities though: it's going to copy the records to a "versioned" table first, and then at a later time the records will be copied by a dif