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, DERBY, EXASOL, INFORMIX, MEMSQL, REDSHIFT, SQLDATAWAREHOUSE, SYBASE, TERADATA, -- YUGABYTEDB /* UNSUPPORTED */
(These are currently generated with jOOQ 3.19, see #10141), or translate your own on our website
Feedback
Do you have any feedback about this page? We'd love to hear it!