Thread: UUID datatype question
In the docs for the uuid datatype it states: (http://www.postgresql.org/docs/8.4/static/datatype-uuid.html) PostgreSQL also accepts the following alternative forms for input: use of upper-case digits, the standard format surroundedby braces, omitting some or all hyphens, adding a hyphen after any group of four digits. Examples are: A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11 {a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11} a0eebc999c0b4ef8bb6d6bb9bd380a11 a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11 {a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11} I can't get the curly bracket ones to work. Everything else works fine. Any idea what am I missing? \d testuuid Table "public.testuuid" Column | Type | Modifiers --------+------+----------- t1 | uuid | Tried with escaping: insert into testuuid values ('\{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11\}'); WARNING: nonstandard use of escape in a string literal LINE 1: insert into testuuid values ('\{a0eebc99-9c0b4ef8-bb6d6bb9-b... ^ HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. ERROR: invalid input syntax for uuid: "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}" Tried w/o escaping: insert into testuuid values ('{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'); ERROR: invalid input syntax for uuid: "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}" Thanks Dave
David Kerr <dmk@mr-paradox.net> writes: > Tried w/o escaping: > insert into testuuid values ('{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'); > ERROR: invalid input syntax for uuid: "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}" Works for me: regression=# select '{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'::uuid; uuid -------------------------------------- a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 (1 row) I wonder whether you are reading the 8.4 docs for an 8.3 installation? (I believe that 8.3 takes braces too ... but it's pickier about where it allows dashes.) regards, tom lane
On Mon, Jul 13, 2009 at 03:28:09PM -0400, Tom Lane wrote: - David Kerr <dmk@mr-paradox.net> writes: - > Tried w/o escaping: - > insert into testuuid values ('{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'); - > ERROR: invalid input syntax for uuid: "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}" - - Works for me: - - regression=# select '{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}'::uuid; - uuid - -------------------------------------- - a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 - (1 row) - - I wonder whether you are reading the 8.4 docs for an 8.3 installation? - - (I believe that 8.3 takes braces too ... but it's pickier about where - it allows dashes.) - - regards, tom lane - Ha, yeah that'd be it. Thanks Dave
Tom Lane wrote: > (I believe that 8.3 takes braces too ... but it's pickier about where > it allows dashes.) This is what the 8.3 comment says: /* * We allow UUIDs in three input formats: 8x-4x-4x-4x-12x, * {8x-4x-4x-4x-12x}, and 32x, where "nx" means n hexadecimal digits * (only the first format is used for output). We convert the first * two formats into the latter format before further processing. */ -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.