Re: UUID as primary key

From: Roman Neuhauser <neuhauser(at)sigpipe(dot)cz>
To: Vance Maverick <vmaverick(at)pgp(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: UUID as primary key
Date: 2006-08-23 13:05:35
Message-ID: 20060823130535.GB99982@dagan.sigpipe.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

# vmaverick(at)pgp(dot)com / 2006-08-21 21:16:14 -0700:
> I'm considering using a UUID as a primary / foreign key for my schema,
> to help ensure portability of data in a multi-master context. Does
> anyone have experience with this?
>
> There's a project on Gborg (pguuid) to create a "native" UUID type, but
> it looks stagnant (and I'd prefer to use PostgreSQL out of the box, if I
> can). So I'm considering three possible representations:
>
> * VARCHAR(36) or CHAR(36) containing the standard textual encoding
> * NUMERIC(40,0) containing the 128-bit binary version of the UUID,
> considered as an integer
> * A pair of BIGINT columns, containing the two 64-bit halves of the
> binary UUID, handled together as a two-column key.
>
> Would any of these give reasonable performance (for joins of large
> tables), compared to int4 IDs? Is any of them clearly any better or
> worse than the others?

Ralf Engelschall's OSSP uuid looks very good. Written in C with
interfaces into PostgreSQL, PHP and C++ (classes wrapping the C
structures and functions).

http://www.ossp.org/pkg/lib/uuid/

You should be able to e. g.

CREATE TABLE t (id UUID DEFAULT 'uuid(4)' PRIMARY KEY);

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2006-08-23 13:07:35 Re: [8.1.4] Create index on timestamp fails
Previous Message Tom Lane 2006-08-23 13:05:19 Re: What's special about 1916-10-01 02:25:20? Odd jump in internal timestamptz representation