From: Dr Frog <drfrog@smartt.com>
To: Steve Wampler <swampler@noao.edu>
To: Poet/Joshua Drake <poet@linuxports.com>
Cc: postgres-sql <pgsql-sql@postgresql.org>
Subject: Re: Using a postgres table to maintain unique id?
Date: 13 Nov 2000 10:30:55 PST
Message-ID: <200011131840.eADIeTa20941@smartt.COM> (raw)
In-Reply-To: <3A102875.C545E345@noao.edu>
References: <Pine.LNX.4.30.0011130925400.2094-100000@crazypenguins.commandprompt.com>
<3A102875.C545E345@noao.edu>
On Mon, 13 Nov 2000 10:44:21 -0700, Steve Wampler said:
> Poet/Joshua Drake wrote:
> >
> > >However, I also use Postgres (7.0.2) throughout this
> > >application and it seems cleaner to me to keep the current
> > >id value in a table and just use postgres to provide access
> > >(with a trigger function to increment the id on access).
> >
> > Why not a sequence?
>
> Can someone show me how to create (and use) an int8 sequence?
>
create sequnece seq_name ;
there are additional options
start sql and type
drfrog=# \h create sequence
Command: CREATE SEQUENCE
Description: Creates a new sequence number generator
Syntax:
CREATE SEQUENCE seqname [ INCREMENT increment ]
[ MINVALUE minvalue ] [ MAXVALUE maxvalue ]
[ START start ] [ CACHE cache ] [ CYCLE ]
drfrog=#
more info in the docs too!
> > >Is this reasonable? Is it fast? (I need 10 or more IDs
> > >generated each second.) Can I avoid having the table
> > >gradually fill with "old" rows for this entry, and this
> > >avoid the need to run VACUUM ANALYZE periodically?
> >
> > The only problem I have had with this type of thing is when a number gets
> > deleted, it does not get recycled.
>
> Fortunately, I don't want any number to ever get recycled - the id needs to
> be unique throughout the 25+ year lifetime of the project. The table
> would have a single row with a single column. Selecting that table cell
> would return the current value, but leave the value incremented in the
> table cell (it's ok if it increments the value before returning).
>
>
> --
> Steve Wampler- SOLIS Project, National Solar Observatory
> swampler@noao.edu
>
>
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: drfrog@smartt.com, swampler@noao.edu, poet@linuxports.com
Subject: Re: Using a postgres table to maintain unique id?
In-Reply-To: <200011131840.eADIeTa20941@smartt.COM>
References: <Pine.LNX.4.30.0011130925400.2094-100000@crazypenguins.commandprompt.com> <3A102875.C545E345@noao.edu> <200011131840.eADIeTa20941@smartt.COM>
* 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