Re: GUID function in pgsql?

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: GUID function in pgsql?
Date: 2005-12-16 17:58:24
Message-ID: 60vexooren.fsf@dba2.int.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

sys(at)meijome(dot)net (Norberto Meijome) writes:

> me(at)alternize(dot)com wrote:
>
>>> Normally you want to use sequences to do this. If you need
>>> something more
>>> global you could combine this with some unique ID for your database.
>>
>>
>> normally i would use serials, of course. but not when the tools
>> expect a guid (i.e. something like
>> 'a4180365-b4b5-4013-bd7b-7b6a386eb343'). and as i'm only in control
>> of the DBMS and not the tools itself, i will need a guid somehow...
>>
> Bruno's advise is still valid. If you google around a bit, you'll
> across explanations like the one in
> http://blogs.msdn.com/oldnewthing/archive/2004/02/11/71307.aspx
>
> on how MS-GUIDs are created. If fitting to your GUID-loving-app is the
> key here, you can easily write a function in C or other language that
> when called it returns a GUID in the exact format you need.
> Somethign like
> substr(random(n,m,sha1(rand(ms_since_epoch())))-[unique ID generated
> from your MAC address]
>
> or something like that - you get the picture.

More appropriate is to link out to the C function/library on your
platform that generates GUIDs.

Linux has one (libuuid); others probably borrow it, or could.

And it seems stupid to me to generate something that is
"handwavy-vaguely similar to GUIDs" rather than doing it *properly*
as per the specs (RFC 4122).

The costs of dealing with "handwavy-similar wasn't good enough" bugs
are likely to be way higher than the costs of reading and following
RFC 4122 in the first place.

There is, after all, a relevant project at gBorg...
<http://gborg.postgresql.org/project/pguuid/projdisplay.php>
--
"cbbrowne","@","ntlug.org"
http://www3.sympatico.ca/cbbrowne/rdbms.html
"Not to oppose error, is to approve of it, and not to defend truth is
to suppress it; not to confound evil men when we can do it, is no less
a sin than to encourage them." -- Pope Felix III, ca. 490

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Danjel Jungersen 2005-12-17 16:10:54 Login problem
Previous Message Lane Van Ingen 2005-12-16 17:51:06 Proper Use of Triggers (and Perhaps Locks)