Unix Technical Forum

GUID function in pgsql?

This is a discussion on GUID function in pgsql? within the pgsql Novice forums, part of the PostgreSQL category; --> hi list i'm looking for a GUID function in pgsql to ease migration from mssql. several tools rely on ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 09:23 PM
me@alternize.com
 
Posts: n/a
Default GUID function in pgsql?

hi list

i'm looking for a GUID function in pgsql to ease migration from mssql. several tools rely on a primary key that consists of a guid column. unfortunately, pgsql does not seem to provide such a datatype, and much worse i wasn't even able to find a similar pgsql function that generates a GUID.

the list archives found some discussions about how a guid could be implemented - unfortunately without giving a final solution. is there really no GUID creation function? if so, could it be requested for a (hopefully not so future) pgsql release?

- thomas
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 09:23 PM
Bruno Wolff III
 
Posts: n/a
Default Re: GUID function in pgsql?

On Thu, Dec 15, 2005 at 05:59:30 +0100,
me@alternize.com wrote:
> hi list
>
> i'm looking for a GUID function in pgsql to ease migration from mssql. several tools rely on a primary key that consists of a guid column. unfortunately, pgsql does not seem to provide such a datatype, and much worse i wasn't even able to find a similar pgsql function that generates a GUID.
>
> the list archives found some discussions about how a guid could be implemented - unfortunately without giving a final solution. is there really no GUID creation function? if so, could it be requested for a (hopefully not so future) pgsql release?
>
> - thomas


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.

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 09:23 PM
me@alternize.com
 
Posts: n/a
Default Re: GUID function in pgsql?

> 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...

- thomas



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 09:23 PM
Norberto Meijome
 
Posts: n/a
Default Re: GUID function in pgsql?

me@alternize.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/ar.../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.
B


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2008, 09:23 PM
me@alternize.com
 
Posts: n/a
Default Re: GUID function in pgsql?

> 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/ar.../11/71307.aspx


i know how a guid is programmatically generated. but that's not the point
here. i'm wondering why pgsql does not come with a predefined function that
already provides this functionality. it would ease the move from other dbms
systems quite alot. it's not about arguing whether or not encoding a
mac-adress into the guid is a good thing. it's more about what people need
when they want to favor pgsql over mssql and migrate existing systems into
the new environement...

Aleksandar Dezelin suggested this project:
> http://gborg.postgresql.org/project/...rojdisplay.php


this seems to provide just about what i would need. the project is not yet
ported to the win32 pgsql version tho, but its author is currently porting
it. would be nice to see it in the next pgsql version's contrib ;-)

- thomas



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2008, 09:23 PM
Bruno Wolff III
 
Posts: n/a
Default Re: GUID function in pgsql?

On Thu, Dec 15, 2005 at 13:04:47 +0100,
me@alternize.com wrote:
> >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/ar.../11/71307.aspx

>
> i know how a guid is programmatically generated. but that's not the point
> here. i'm wondering why pgsql does not come with a predefined function that
> already provides this functionality. it would ease the move from other dbms
> systems quite alot. it's not about arguing whether or not encoding a
> mac-adress into the guid is a good thing. it's more about what people need
> when they want to favor pgsql over mssql and migrate existing systems into
> the new environement...


Probably because it is not very general and it is easy to generate a string
matching whatever format your app expects without much work.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-17-2008, 09:24 PM
Chris Browne
 
Posts: n/a
Default Re: GUID function in pgsql?

sys@meijome.net (Norberto Meijome) writes:

> me@alternize.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/ar.../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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com