diff options
author | Peter Eisentraut | 2019-07-14 12:30:27 +0000 |
---|---|---|
committer | Peter Eisentraut | 2019-07-14 12:30:27 +0000 |
commit | 5925e5549890416bcf588334d9d0bc99f8ad6c7f (patch) | |
tree | 0b9d6556f5e4dcaa389d2f35cf60804645d2c5f8 /src/test | |
parent | 565f3390005318ea4c982b8d054d56e9fe5a6454 (diff) |
Add gen_random_uuid function
This adds a built-in function to generate UUIDs.
PostgreSQL hasn't had a built-in function to generate a UUID yet,
relying on external modules such as uuid-ossp and pgcrypto to provide
one. Now that we have a strong random number generator built-in, we
can easily provide a version 4 (random) UUID generation function.
This patch takes the existing function gen_random_uuid() from pgcrypto
and makes it a built-in function. The pgcrypto implementation now
internally redirects to the built-in one.
Reviewed-by: Fabien COELHO <[email protected]>
Discussion: https://www.postgresql.org/message-id/[email protected]
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/opr_sanity.out | 1 | ||||
-rw-r--r-- | src/test/regress/expected/uuid.out | 10 | ||||
-rw-r--r-- | src/test/regress/sql/uuid.sql | 6 |
3 files changed, 17 insertions, 0 deletions
diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out index 85af36ee5bc..33c058ff514 100644 --- a/src/test/regress/expected/opr_sanity.out +++ b/src/test/regress/expected/opr_sanity.out @@ -742,6 +742,7 @@ sha224(bytea) sha256(bytea) sha384(bytea) sha512(bytea) +gen_random_uuid() starts_with(text,text) macaddr8_eq(macaddr8,macaddr8) macaddr8_lt(macaddr8,macaddr8) diff --git a/src/test/regress/expected/uuid.out b/src/test/regress/expected/uuid.out index db66dc723ef..090103df48a 100644 --- a/src/test/regress/expected/uuid.out +++ b/src/test/regress/expected/uuid.out @@ -145,5 +145,15 @@ SELECT COUNT(*) FROM guid1 g1 LEFT JOIN guid2 g2 ON g1.guid_field = g2.guid_fiel 1 (1 row) +-- generation test +TRUNCATE guid1; +INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid()); +INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid()); +SELECT count(DISTINCT guid_field) FROM guid1; + count +------- + 2 +(1 row) + -- clean up DROP TABLE guid1, guid2 CASCADE; diff --git a/src/test/regress/sql/uuid.sql b/src/test/regress/sql/uuid.sql index 518d2b75c00..3bd3b357c77 100644 --- a/src/test/regress/sql/uuid.sql +++ b/src/test/regress/sql/uuid.sql @@ -75,5 +75,11 @@ INSERT INTO guid2(guid_field) VALUES('3f3e3c3b3a3039383736353433a2313e'); SELECT COUNT(*) FROM guid1 g1 INNER JOIN guid2 g2 ON g1.guid_field = g2.guid_field; SELECT COUNT(*) FROM guid1 g1 LEFT JOIN guid2 g2 ON g1.guid_field = g2.guid_field WHERE g2.guid_field IS NULL; +-- generation test +TRUNCATE guid1; +INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid()); +INSERT INTO guid1 (guid_field) VALUES (gen_random_uuid()); +SELECT count(DISTINCT guid_field) FROM guid1; + -- clean up DROP TABLE guid1, guid2 CASCADE; |