4

I've got a query storing a UUIDv4 as a byte type in CockroachDB (v1.0). Its generated with Cockroach's documented 'uuid_v4()' function. When making selections, the results will return with the byte-typed format, like so:

"\x9d\xce`\xb3p\x9aKB\xbe\xba\xeb\xec~\x9e\xfb\x93"

while the goal is to have it output a string uuidv4, like:

"abcd-12345-asdifoekc"

I've read the casting docs on: https://www.cockroachlabs.com/docs/data-types.html#data-type-conversions--casts but still cannot figure out how to do this conversion during a SELECT statement.

jiveTurkey
  • 689
  • 3
  • 7
  • 17

1 Answers1

4

Use the from_uuid() builtin, as follows:

root@:26257/> SELECT from_uuid(uuid_v4());
+--------------------------------------+
|         from_uuid(uuid_v4())         |
+--------------------------------------+
| 4817bb15-4d93-4b77-b7d1-1e5cfb8360e3 |
+--------------------------------------+
(1 row)
Jordan Lewis
  • 16,900
  • 4
  • 29
  • 46