Re: Unique record Identifier?
От | Josh Berkus |
---|---|
Тема | Re: Unique record Identifier? |
Дата | |
Msg-id | web-64491@davinci.ethosmedia.com обсуждение исходный текст |
Ответ на | Unique record Identifier? ("Chris Ruprecht" <chrup999@yahoo.com>) |
Ответы |
Re: Unique record Identifier?
|
Список | 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 informationtechnology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-sql по дате отправления: