Last active
June 17, 2024 20:18
-
-
Save keisisqrl/50ccccd353e3ebf293a6fd09102e06aa to your computer and use it in GitHub Desktop.
uuidgen for sqlite
This file contains 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
/* uuidgen.sql | |
* | |
* creates a view uuidgen(uuid TEXT) which generates v4 UUIDs on demand | |
* generated per RFC 4122 | |
* | |
* it's not a stored procedure exactly but subqueries are allowed in | |
* any expression | |
**/ | |
CREATE VIEW uuidgen AS | |
SELECT printf('%x-%x-%x-%x-%x', | |
random() & 0xffffffff, | |
random() & 0xffff, | |
random() & 0x0fff | 0x4000, -- version 4, random uuid | |
random() & 0x3fff | 0x8000, -- variant 1, RFC 4122 uuid | |
random() & 0xffffffffffff) | |
AS uuid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment