Re: Unique record Identifier?

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Chris Ruprecht" <chrup999(at)yahoo(dot)com>, "psql" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Unique record Identifier?
Date: 2001-05-30 21:33:02
Message-ID: web-64491@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Linh Luong 2001-05-30 22:37:58 Using indexes
Previous Message Frank Contrepois 2001-05-30 21:31:54 Re: INSERT value of type table