473,508 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUIDs

Hi All,

I want to use GUIDs for object IDs in my application. This means that
they would be used for primary keys in PostgreSQL, and there would of
course be FKs pointing to them. A GUID is 128 bits, and can be in the
following possible formats:

* 16 byte binary (but then I'd have to convert it to hex in my app)
* 32 byte string (e.g., '4162F7121DD211B2B17EC09EFE1DC403')
* hex string (e.g., 0x3271839C163D11D891F785398CC7932E)
* Base 64 string (e.g., 'MnIAdBY9EdiR94U5jMeTLg==')

It looks like the hex option would be the best option, but there's no
native hex format in PostgreSQL. Anyone have suggestions on what the
best approach might be? I can't convert it to a number, really, because
128 bit numbers aren't too portable).

Please Cc any replies to me, as I'm not subscribed to the mail list.

Many TIA,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
14 2696
David Wheeler writes:
It looks like the hex option would be the best option, but there's no
native hex format in PostgreSQL. Anyone have suggestions on what the
best approach might be? I can't convert it to a number, really, because
128 bit numbers aren't too portable).


Use bytea. It stores bytes and allows the conversion into several output
formats.

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #2
On Thursday, November 13, 2003, at 08:04 PM, Peter Eisentraut wrote:
Use bytea. It stores bytes and allows the conversion into several
output
formats.


bytea with the binary or the hex? And isn't it a bit of a waste to add
the extra 4 bytes when I'll only ever need 16?

Thanks,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #3
David Wheeler writes:
bytea with the binary or the hex?
Binary or hex what?
And isn't it a bit of a waste to add the extra 4 bytes when I'll only
ever need 16?


Sure, but if you want to avoid that, you'll have to implement your own
data type. Actually, I think someone has already done that for GUID. If
you search the archives you might find out about it.

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #4
On Thursday, November 13, 2003, at 08:30 PM, Peter Eisentraut wrote:
Bbytea with the binary or the hex?

Binary or hex what?


Representation of the UUID.
And isn't it a bit of a waste to add the extra 4 bytes when I'll only
ever need 16?


Sure, but if you want to avoid that, you'll have to implement your own
data type. Actually, I think someone has already done that for GUID.
If
you search the archives you might find out about it.


Sure enough. Josh just mentioned this to me:

http://gborg.postgresql.org/project/...rojdisplay.php

Looks like 1.0.0 was released June 17, 2003. I wonder how robust it is?

Cheers,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #5
On Thu, Nov 13, 2003 at 19:57:33 -0500,
David Wheeler <da***@kineticode.com> wrote:
Hi All,

I want to use GUIDs for object IDs in my application. This means that
they would be used for primary keys in PostgreSQL, and there would of
course be FKs pointing to them. A GUID is 128 bits, and can be in the
following possible formats:


Couldn't you use numeric? That should be fairly portable.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #6
On Friday, November 14, 2003, at 12:04 AM, Bruno Wolff III wrote:
Couldn't you use numeric? That should be fairly portable.


Not really. The GUID is 128 bits, which doesn't work so well on 32-bit
systems.

Regards,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #7
David Wheeler <da***@kineticode.com> writes:
On Friday, November 14, 2003, at 12:04 AM, Bruno Wolff III wrote:
Couldn't you use numeric? That should be fairly portable.


Not really. The GUID is 128 bits, which doesn't work so well on 32-bit
systems.


NUMERIC is an arbitrary-precision integer, not a machine word.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #8
On Friday, November 14, 2003, at 06:18 PM, Doug McNaught wrote:
NUMERIC is an arbitrary-precision integer, not a machine word


Yeah, but that doesn't help me in Perl.

Regards,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #9
On Fri, Nov 14, 2003 at 17:52:41 -0500,
David Wheeler <da***@kineticode.com> wrote:
On Friday, November 14, 2003, at 12:04 AM, Bruno Wolff III wrote:
Couldn't you use numeric? That should be fairly portable.


Not really. The GUID is 128 bits, which doesn't work so well on 32-bit
systems.


On postgres numeric isn't limited to what can be represented in 32 bits.
I am not sure about other systems, but I would expect it to not be limited
to just 32 bits on them either.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #10
On Fri, Nov 14, 2003 at 18:26:27 -0500,
David Wheeler <da***@kineticode.com> wrote:
On Friday, November 14, 2003, at 06:18 PM, Doug McNaught wrote:
NUMERIC is an arbitrary-precision integer, not a machine word


Yeah, but that doesn't help me in Perl.


You can probably keep it as a string in perl. There are also large number
handling routines available for perl if you really need to treat it
as a number there.

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

http://archives.postgresql.org

Nov 12 '05 #11
On Friday, November 14, 2003, at 11:20 PM, Bruno Wolff III wrote:
Yeah, but that doesn't help me in Perl.


You can probably keep it as a string in perl. There are also large
number
handling routines available for perl if you really need to treat it
as a number there.


I can store them as a string in Perl, but the trick is getting the
string representation in the first place. The library I was looking at
using Data::UUID, offers binary and hex representations, as well as a
32 bit alphanumeric string and a Base64-encoded string, but not a
numeric string, unfortunately.

http://search.cpan.org/dist/Data-UUID/UUID.pm

Regards,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #12
David Wheeler <da***@kineticode.com> writes:
I can store them as a string in Perl, but the trick is getting the
string representation in the first place. The library I was looking at
using Data::UUID, offers binary and hex representations, as well as a
32 bit alphanumeric string and a Base64-encoded string, but not a
numeric string, unfortunately.


I think if I were in your place, I'd store them as TEXT fields using
either the base64 or hex representation.

-Doug

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

Nov 12 '05 #13
Doug McNaught wrote:
David Wheeler <da***@kineticode.com> writes:
On Friday, November 14, 2003, at 12:04 AM, Bruno Wolff III wrote:
> Couldn't you use numeric? That should be fairly portable.


Not really. The GUID is 128 bits, which doesn't work so well on 32-bit
systems.


NUMERIC is an arbitrary-precision integer, not a machine word.


No, NUMERIC is an arbitrary precision _numeric_ type that uses string
math internally. Want log(2.0) with 200 digits precision?
Jan

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #14
On Saturday, November 15, 2003, at 05:26 PM, Doug McNaught wrote:
I think if I were in your place, I'd store them as TEXT fields using
either the base64 or hex representation.


That was my original plan. But because the hex and base64
representations are 32 bytes instead of 16, it ends up being a lot less
efficient. Josh Berkus explains it to me like this:

<agliodbs> I mean, think of, for example, many-to-many join tables, or
tree tables, with millions of rows but just to id columns
<agliodbs> going from 32 bytes per row to 64 bytes will almost double
the size of the table and all of its indexes
<agliodbs> for example, let's take the join table/index example:
1000000 rows, with 2 ID colmuns
<agliodbs> now, usling a 16byte number, you have about 40bytes per row
(16+16+overhead)
<agliodbs> that's 40mb to load the table/index into memory
<agliodbs> but if you go with 32chars, that's about 76mb ... or abut
120mb for unicode
<agliodbs> hopefully you're not loading the whole thing into memory
often, but sometimes seq scans are necessary, and as much as 1/3 of the
table could end up in memory
<agliodbs> in addition to the memory load, it takes longer to get 40 mb
off disk than it does to take 13mb
<agliodbs> and longer to sync it to disk, and longer to vacuum it

So I'm inclined, I think, to use BYTEA as Peter originally suggested (I
can't get pguuid to compile for PostgreSQL 7.3.3 or 7.4RC2) and convert
it to other representations as needed on the API.

Regards,

David

--
David Wheeler AIM: dwTheory
da***@kineticode.com ICQ: 15726394
http://www.kineticode.com/ Yahoo!: dew7e
Jabber: Th****@jabber.org
Kineticode. Setting knowledge in motion.[sm]
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3129
by: Jon Perez | last post by:
Is there a Python function that works on all platforms (not just Win32) to generate such in the DCE / Microsoft format? If not present, this looks like it would be a very Pythonic addition to...
0
1352
by: Shaun Clark | last post by:
Hello, I am trying to bring my entire organization from a Microsoft platform to a Linux one, starting with all of the servers we are currently running. Sun ONE ASP allows me to run ASP on Linux...
8
1378
by: Roland Hall | last post by:
Would a GUID be a good idea to use for a random generated account code. The user will be given a link to pass the GUID and then be prompted for a password. Ex....
4
33845
by: J.Marsch | last post by:
I notice that when I generate various guids, they appear to have a mix of upper and lowercase letters. Is the uniqueness of a guid case-sensitive? In other words, if I generate a guid, and...
1
10873
by: vector | last post by:
I've got an application that generates GUIDs. A lot of GUIDs. Lots of GUIDs that end up in files on disk, taking up space. I'd like to continue using the Guid.NewGuid() function as my unique tag...
1
1234
by: Andrew S. Giles | last post by:
Hello, I am writing a COM interface to one of my classes, so that the interface bmay be used to provide a means of sending data from a legacy code application to the new .NET user Interface. ...
11
7217
by: Jeff | last post by:
Hi - I'm experiencing a strange problem when comparing 2 guids. In my trial, they're not equal. When I step through the (VB.NET) code, they are evaluated as equal, and when I enter the...
2
1145
by: Howard Kaikow | last post by:
Being lazy, I sometimes copy a project to another directory, then tweak the code. A problem arises because then both projects have identical GUIDs in the .sln file, and in the assembly file. ...
14
2693
by: Chris Dunaway | last post by:
I have used Guid's as a unique identifier in data applications. But in a recent project, the length of the Guid's string is proving to be too long. Is there a method for generating a unique...
1
2132
by: GHUM | last post by:
Hello, I created lots of guids via pywintypes.CreateGuid() on windows. Now I would like to run the same software on Linux / Solaris / FreeBSD. So I should produce "compatible" GUIDS on...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.