pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedUnique record Identifier?
3+ messages / 2 participants
[nested] [flat]
* Unique record Identifier?
@ 2001-05-30 20:14 Chris Ruprecht <chrup999@yahoo.com>
2001-05-30 21:33 ` Re: Unique record Identifier? Josh Berkus <josh@agliodbs.com>
0 siblings, 1 reply; 3+ messages in thread
From: Chris Ruprecht @ 2001-05-30 20:14 UTC (permalink / raw)
To: pgsql-sql
Hi all,
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?
Best regards,
Chris
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Unique record Identifier?
2001-05-30 20:14 Unique record Identifier? Chris Ruprecht <chrup999@yahoo.com>
@ 2001-05-30 21:33 ` Josh Berkus <josh@agliodbs.com>
2001-05-30 23:11 ` Re: Unique record Identifier? Chris Ruprecht <chrup999@yahoo.com>
0 siblings, 1 reply; 3+ messages in thread
From: Josh Berkus @ 2001-05-30 21:33 UTC (permalink / raw)
To: Chris Ruprecht <chrup999@yahoo.com>; 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@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Unique record Identifier?
2001-05-30 20:14 Unique record Identifier? Chris Ruprecht <chrup999@yahoo.com>
2001-05-30 21:33 ` Re: Unique record Identifier? Josh Berkus <josh@agliodbs.com>
@ 2001-05-30 23:11 ` Chris Ruprecht <chrup999@yahoo.com>
0 siblings, 0 replies; 3+ messages in thread
From: Chris Ruprecht @ 2001-05-30 23:11 UTC (permalink / raw)
To: pgsql-sql
on 05/30/2001 16:33, Josh Berkus at josh@agliodbs.com wrote:
> Chris,
>
Thanks Josh - that was my next step. At the moment, the database is not in
production, I'm running a Progress database there, but I'm trying to learn
the dos and don'ts in PG. I don't really need to backfill the records, I can
just drop the table and re-create it (On my Mac PowerBook it loads 1.2
million records in about 5 minutes without any index on the table).
I'm sure, I will have many more questions in the future ...
Best regards,
Chris
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-05-30 23:11 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-30 20:14 Unique record Identifier? Chris Ruprecht <chrup999@yahoo.com>
2001-05-30 21:33 ` Josh Berkus <josh@agliodbs.com>
2001-05-30 23:11 ` Chris Ruprecht <chrup999@yahoo.com>
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