From: Josh Berkus <josh@agliodbs.com>
To: Chris Ruprecht <chrup999@yahoo.com>
To: psql <pgsql-sql@postgresql.org>
Subject: Re: Unique record Identifier?
Date: Wed, 30 May 2001 14:33:02 -0700
Message-ID: <web-64491@davinci.ethosmedia.com> (raw)
In-Reply-To: <008101c0e945$1bf489c0$5dd26383@corp.compucom.com>
Chris,
> I'm busy writing an application using PostGreSQL and PHP, so my db
> reads are
> 'stateless' and I don't know at record 'write' time which record I
> have read
> to begin with. The records I have, have an index, most tables do have
> a
> unique index but the index values could get changed during an update.
> In
> order to be able to re-read a record, I would like to use some unique
> identifier of that record, like a unique db-wide rec-id. Does this
> exist in
> PostGres and if so, how do I access it?
One does -- the OID. However, for various reasons (already discussed ad
naseum on this list) you don't want to use the OID as your client side
unique index. Instead, you'll want to "roll your own" global unique id:
1. Create a sequence ('gui_sq'). Set it to start at a number that will
allow you to backfill exisiting records.
2. Add a column of type INT4 to each table ('gsq')
3. Create the default value of this column as NEXTVAL('gui_sq').
4. Backfill existing records.
5. Add a unique index on each table for this column.
You now have a unique identifier that is unique not only for each table
but between tables.
-Josh
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
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: josh@agliodbs.com, chrup999@yahoo.com
Subject: Re: Unique record Identifier?
In-Reply-To: <web-64491@davinci.ethosmedia.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