Skip site navigation (1) Skip section navigation (2)

Re: resetting primary key after copy

From: "Derrick Betts" <list(at)blueaxis(dot)com>
To: "Don Guernsey" <dononyx(at)yahoo(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: resetting primary key after copy
Date: 2007-02-12 18:00:32
Message-ID: 028201c74ecf$b10378a0$0202a8c0@main (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
> 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.


In response to

pgsql-novice by date

Next:From: Yumiko IzumiDate: 2007-02-13 02:16:45
Subject: pq_flush: send() failed: Broken pipe
Previous:From: Andrej Ricnik-BayDate: 2007-02-12 17:46:10
Subject: Re: resetting primary key after copy

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group