advancing sequences

From: "Dmitri Bichko" <dbichko(at)genpathpharma(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: advancing sequences
Date: 2003-05-06 16:13:44
Message-ID: 7A4ADADFC8AFF0478D47F63BEDD57CE30D08FA@gpmail.gphq.genpathpharma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to speed up a couple of decent sized inserts (~25K rows a
pop) by using COPY FROM.
A slight snag I am running into is that the table I insert into has a
primary key generated from a sequence.
So I want to include this id in the temp text file that I copy from, so
what is the proper way to grab 25K or so values from a sequence, without
breaking anything?

In other words, if I get $current_val with "nextval('foo')" and then do
a "setval('foo', $current_val + 25000)", that creates a race condition.
The only other thing I can think of is "setval('foo', nextval('foo') +
25000)", but then I can't get the actual start value out (and I am not
even sure this would be truly atomic).

What's the proper way of doing this? Calling nextval for every row when
I create the temp file seems to somehow go against the idea of speeding
things up...

thanks,
Dmitri

Responses

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2003-05-06 16:38:06 Re: Database server restarting
Previous Message Dennis Gearon 2003-05-06 15:51:30 Re: Database server restarting