UUID
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
The UUID()
function generates a new random UUID
SELECT uuid();
create.select(uuid()).fetch();
The result being
+--------------------------------------+ | uuid | +--------------------------------------+ | 1fc454e5-b9f6-4d55-b783-5987fe76cb45 | +--------------------------------------+
Dialect support
This example using jOOQ:
uuid()
Translates to the following dialect specific expressions:
Access
genguid()
ASE
newid(-1)
BigQuery
generate_uuid()
CockroachDB, Postgres
gen_random_uuid()
DB2
CAST(regexp_replace((hex(rand()) || hex(generate_unique())), '(.{8})(.{4})(.{4})(.{4})(.{12}).*', '$1-$2-$3-$4-$5') AS char(36))
DuckDB, HSQLDB, MariaDB, MySQL, Trino
uuid()
Firebird
uuid_to_char(gen_uuid())
H2
random_uuid()
Hana
CAST(replace_regexpr('(.{8})(.{4})(.{4})(.{4})(.{12}).*' IN CAST(sysuuid AS char(36)) WITH '\1-\2-\3-\4-\5') AS char(36))
Oracle
CAST(regexp_replace(rawtohex(sys_guid()), '(.{8})(.{4})(.{4})(.{4})(.{12}).*', '\1-\2-\3-\4-\5') AS varchar2(36))
Snowflake
uuid_string()
SQLite
( SELECT (substr(u, 1, 8) || '-' || substr(u, 9, 4) || '-' || substr(u, 13, 4) || '-' || substr(u, 17, 4) || '-' || substr(u, 21)) FROM ( SELECT lower(hex(randomblob(16))) u ) t )
SQLServer
newid()
Vertica
uuid_generate()
Aurora MySQL, Aurora Postgres, ClickHouse, Derby, Exasol, Informix, MemSQL, Redshift, SQLDataWarehouse, Sybase, Teradata, YugabyteDB
/* UNSUPPORTED */
Generated with jOOQ 3.20. Translate your own SQL on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!