Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4ULX5E84724 for ; Wed, 30 May 2001 17:33:05 -0400 (EDT) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 64491; Wed, 30 May 2001 14:33:02 -0700 From: "Josh Berkus" Subject: Re: Unique record Identifier? To: "Chris Ruprecht" , "psql" X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Wed, 30 May 2001 14:33:02 -0700 Message-ID: In-Reply-To: <008101c0e945$1bf489c0$5dd26383@corp.compucom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200105/347 X-Sequence-Number: 3188 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