Thread: resetting primary key after copy

resetting primary key after copy

From
Don Guernsey
Date:
does anyone know how to do this? I need to reset the primary key after I copy a
bunch of data to postgres. The other option would be to start my tables primary
key at a high number, like 3000000. Any Ideas?



____________________________________________________________________________________
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail

Re: resetting primary key after copy

From
"A. Kretschmer"
Date:
am  Mon, dem 12.02.2007, um  9:28:40 -0800 mailte Don Guernsey folgendes:
> does anyone know how to do this? I need to reset the primary key after I copy a

Why? Do you want to break the primary key? You can use setval() for
this.
http://www.postgresql.org/docs/8.1/interactive/functions-sequence.html


> bunch of data to postgres. The other option would be to start my tables primary
> key at a high number, like 3000000. Any Ideas?

Also with setval() or create sequence foo start 300000;


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: resetting primary key after copy

From
"Andrej Ricnik-Bay"
Date:
On 2/13/07, Don Guernsey <dononyx@yahoo.com> wrote:
> does anyone know how to do this? I need to reset the
> primary key after I copy a bunch of data to postgres.
> The other option would be to start my tables primary
> key at a high number, like 3000000. Any Ideas?
Just  a question:  what do you mean by "reset the primary
key"?



Cheers,
Andrej

Re: resetting primary key after copy

From
"Derrick Betts"
Date:
> does anyone know how to do this? I need to reset the primary key after I
> copy a
> bunch of data to postgres. The other option would be to start my tables
> primary
> key at a high number, like 3000000. Any Ideas?
>
>
This may not be a very smart idea (depending on if you have foreign keys, or
links to the primary key from other tables, etc.), but perhaps you can copy
your table, then delete your primary key, then delete the primary key
column, then add a new primary key column, then create a function that adds
unique numbers to the new column, then add the primary key constraint back
into your table.

Lots of work, but if it is what you are looking for... Keep in mind, I'm a
novice reading a NOVICE list.

Derrick