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

[NOVICE] Skipping numbers in a sequence.

From: GH <grasshacker(at)over-yonder(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] Skipping numbers in a sequence.
Date: 2000-11-23 19:44:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-novice
Hello all.

It's like this. ;-)

I have a table with a column that has a default nextval('sequence').
The sequence is a standard increment 1 cycle sequence.

What happens when
	the sequence wraps after inserting the 
		2-million-and-whatever-th row 
	some of the earlier 
		rows (say, 1-100) are still in the table
	but other rows or sections (say, 101-110 and 120-125) have 
		been deleted
and I need to begin with the first un-used sequence number?

I suppose that I would need to find the first un-used sequence number, 
use setval() to update the sequence, and then insert the row that needs
to be insert-ed. Well, how can I find the first un-used sequence number?
I thought about doing something using a function like
	select sequence_column from table
	NOT [the set of numbers that make up the sequence]
but, how do I select the set of numbers that make up the sequence?

Is there a better/cleaner/easier way of getting the end result?

Postgres 7.0.2 (should be running .3, *sigh*)
PHP 4.0.3pl1

Thanks fellas (and ladies, if applicable).



pgsql-novice by date

Next:From: Paul McGarryDate: 2000-11-24 04:17:59
Subject: Re: re : PHP and persistent connections
Previous:From: Alfred PerlsteinDate: 2000-11-23 19:31:53
Subject: Re: startup script for FreeBSD

pgsql-general by date

Next:From: Peter EisentrautDate: 2000-11-23 20:13:09
Subject: Re: pgaccess
Previous:From: Jose Manuel Lorenzo LopezDate: 2000-11-23 18:24:03
Subject: Compiling postgresql 7.0.3 for WinNT

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