pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PFC <lists@boutiquenumerique.com>
To: Andrew Sullivan <ajs@crankycanuck.ca>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: Column with recycled sequence value
Date: Fri, 14 Jan 2005 02:27:27 +0100
Message-ID: <opskkjn1arth1vuj@musicbox> (raw)
In-Reply-To: <20050113194900.GB31858@phlogiston.dyndns.org>
References: <ED4E30DD9C43D5118DFB00508BBBA76EB1654B@neptun.sonorys.at>
	<20050113194900.GB31858@phlogiston.dyndns.org>


	You could update all the fields which use this sequence number. You say  
you have a lot of activity so you must have mahy holes in your sequence,  
probably of the possible 2^32 values, only a fes millions are used.

	You can do the following :

	- Take down the database, back it up, and restart it with a single user,  
so only you can connect, using psql.
	- Create a table :
CREATE TABLE translate ( new_id SERIAL PRIMARY KEY, old_id INTEGER,  
UNIQUE(old_id) ) WITHOUT OIDS;

	- Insert into this table all the used sequence values you have in your  
database. If you have all the proper constraints, these should come from  
only one table, so it should be straightformard :

INSERT INTO translate (old_id) SELECT id FROM your_table;

	Thus the "translate" table maps old id's to a new sequence that you just  
started, and that means your new id's will be compactly arranged, starting  
at 1.

	- Update your existing table, joining it to the translate table, to  
replace the old id by the new id.


> On Thu, Jan 13, 2005 at 06:08:20PM +0100, KÖPFERL Robert wrote:
>> Hi,
>>
>> suppose I have a let's say heavy used table. There's a column containing
>> UNIQUE in4
>> values. The data type musn't exceed 32-Bit. Since however the table is  
>> heavy
>> used 2^32 will be reached soon and then? There are far less than  
>> 4G-records
>> saved thus these values may be reused. How can this be accomplished?
>
> You can set the sequence up to cycle (so once it gets to the end, it
> wraps around to the beginning again).  The keyword is CYCLE at CREATE
> SEQUENCE time.  It defaults to NO CYCLE.
>
> One potential problem, of course, are collisions on the table,
> because some value wasn't cleared out.  It sounds like you don't have
> that problem though.
>
> A
>





view thread (13+ messages)  latest in thread

Message-ID: <opskkjn1arth1vuj@musicbox>
Permalink:  ../opskkjn1arth1vuj@musicbox/
Also on:    postgresql.org/message-id/opskkjn1arth1vuj@musicbox

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: lists@boutiquenumerique.com, ajs@crankycanuck.ca
  Subject: Re: Column with recycled sequence value
  In-Reply-To: <opskkjn1arth1vuj@musicbox>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox