Last active
December 29, 2020 23:40
-
-
Save fabiolimace/f9a55bd29e4e054fc4de27410ae620c3 to your computer and use it in GitHub Desktop.
Select statement for generating random UUIDs (v4) on PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Generate a random-based UUID (v4) | |
| * | |
| * RFC-4122 compliant. | |
| * | |
| * Tags: uuid guid uuid-generator guid-generator generator random rfc4122 rfc-4122 | |
| */ | |
| select (overlay(overlay(md5(random()::text || random()::text || current_timestamp::text) placing '4' from 13) placing ( to_hex(8 + (extract(microseconds from statement_timestamp())::integer % 4)) ) from 17))::uuid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment