5

I see http://www.ietf.org/rfc/rfc4122.txt

What's the maximum length of a RFC 4122 version 4? In other words, is it always the same maximum length as this example string value taken from the document? f81d4fae-7dec-11d0-a765-00a0c91e6bf6

I think the answer lies in the section that says "The formal definition of the UUID string representation is provided by the following ABNF"

I wanted a second opinion for the sake of a database table column (varchar).

Thanks!

finneycanhelp
  • 9,018
  • 12
  • 53
  • 77
  • I have no answer, but which database server are you using? Some databases have types dedicated to storing UUIDs. SQL Server for example has the `uniqueidentifier` type. – Rickard Andersson Feb 25 '13 at 12:02
  • good question. oracle. I see "There is no GUID or uniqueidentifier type in Oracle" according to http://www.michelrenaud.com/?p=3 – finneycanhelp Feb 25 '13 at 12:08
  • [Related question](http://stackoverflow.com/questions/153815/how-should-i-store-a-guid-in-oracle). – Rickard Andersson Feb 25 '13 at 12:12

1 Answers1

9

According to RFC 4122:

A UUID is 128 bits long, and can guarantee uniqueness across space and time.

But if we want to know the string representation, we need to check the ABNF:

  UUID                   = time-low "-" time-mid "-"
                           time-high-and-version "-"
                           clock-seq-and-reserved
                           clock-seq-low "-" node
  time-low               = 4hexOctet
  time-mid               = 2hexOctet
  time-high-and-version  = 2hexOctet
  clock-seq-and-reserved = hexOctet
  clock-seq-low          = hexOctet
  node                   = 6hexOctet
  hexOctet               = hexDigit hexDigit
  hexDigit =
        "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" /
        "a" / "b" / "c" / "d" / "e" / "f" /
        "A" / "B" / "C" / "D" / "E" / "F"

We have a total of 16 hexOctet. We count 2 characters by hexOctet plus 4 times the character "-". We have a total of 16 * 2 + 4 = 36 characters regardless of the version.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240