should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
# name: test/sql/function/uuid/test_uuid.test
# description: Test gen_random_uuid function
# group: [uuid]
statement ok
BEGIN TRANSACTION
statement ok
CREATE TEMPORARY TABLE t1 AS SELECT gen_random_uuid() a FROM range(0, 16);
statement ok
CREATE TEMPORARY TABLE t2 AS SELECT uuid() b FROM range(0, 16);
statement ok
CREATE TEMPORARY TABLE t3 AS SELECT gen_random_uuid() c FROM range(0, 16);
# empty result on this join
query I
SELECT COUNT(*) FROM (SELECT a FROM t1 JOIN t2 ON (a=b) JOIN t3 ON (b=c)) s1
----
0
statement ok
ROLLBACK
# use gen_random_uuid in some complicated expressions
statement ok
CREATE TABLE uuids(u UUID NOT NULL DEFAULT gen_random_uuid(), a INTEGER);
statement ok
INSERT INTO uuids (a) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
query I
SELECT COUNT(DISTINCT u) FROM uuids;
----
10
# we can order by gen_random_uuid
statement ok
SELECT * FROM uuids ORDER BY gen_random_uuid();
# we can select gen_random_uuid, uuidv4, uuidv7
statement ok
SELECT gen_random_uuid() FROM uuids;
SELECT uuidv4() FROM uuids;
SELECT uuidv7() FROM uuids;
# UUID v4 follows `XXXXXXXX-XXXX-4XXX-XXXX-XXXXXXXXXXXX` format
query I
SELECT DISTINCT substring(uuid()::varchar, 15, 1) FROM range(100);
----
4
query I
SELECT DISTINCT substring(uuidv4()::varchar, 15, 1) FROM range(100);
----
4
# UUID v7 follows `XXXXXXXX-XXXX-7XXX-XXXX-XXXXXXXXXXXX` format
query I
SELECT DISTINCT substring(uuidv7()::varchar, 15, 1) FROM range(100);
----
7
# UUID v4 variant 1 follows `XXXXXXXX-XXXX-4XXX-[89ab]XXX-XXXXXXXXXXXX` format
# the probability for 100 iters not to cover the 4 possible values is (3/4)**100 == 3e-13
query I
SELECT DISTINCT substring(uuid()::varchar, 20, 1) AS x FROM range(100) ORDER BY x
----
8
9
a
b

View File

@@ -0,0 +1,52 @@
# name: test/sql/function/uuid/test_uuid_function.test
# description: Test uuid related functions
# group: [uuid]
query I
SELECT uuid_extract_version('ac227128-7d55-7ee0-a765-5025cc52e55a');
----
7
query I
SELECT uuid_extract_version(uuidv7());
----
7
# Test UUIDv4 in string format.
query I
SELECT uuid_extract_version('ac227128-7d55-4ee0-a765-5025cc52e55a');
----
4
query I
SELECT uuid_extract_version(uuidv4());
----
4
query I
SELECT uuid_extract_version(gen_random_uuid());
----
4
# Test timestamp extraction with UUID v4.
statement error
SELECT uuid_extract_timestamp(uuidv4());
----
Given UUID is with version 4, not version 7.
require icu
statement ok
SET TimeZone='UTC'
# Test timestamp extraction with UUID v7.
query I
SELECT uuid_extract_timestamp('0196f97a-db14-71c3-9132-9f0b1334466f');
----
2025-05-22 19:31:40.436+00
# verify the generated timestamp is consistent with NOW()
query I
SELECT datediff('month', uuid_extract_timestamp(uuidv7()), now());
----
0