Re: autoupdate sequences after copy

From: Richard Huxton <dev(at)archonet(dot)com>
To: CSN <cool_screen_name90001(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: autoupdate sequences after copy
Date: 2003-10-09 09:02:58
Message-ID: 200310091002.58970.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday 09 October 2003 08:10, CSN wrote:
> Is there a way to have p/k sequences get automatically
> set to max(id)+1 after COPY's like the following?
>
> copy table1 (id,name) from stdin;
> 1 abc
> 2 def
> 3 fhi
> \.

Not really - if you don't use the sequence it keeps its value. If you look at
pg_dump it issues an explicit setval() after a copy.

I'm not sure you can even work around it with a BEFORE trigger to check and
update the sequence, the nextval() call will probably be processed before the
trigger gets called (haven't checked). In any case, performance would be a
bit poor.

Is there any reason why you're supplying your own id values when you already
have a sequence?

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message sibusiso xolo 2003-10-09 09:03:01 help with large objects in 7.3.4
Previous Message Harald Fuchs 2003-10-09 08:52:50 Re: Generating a SQL Server population routine