Skip to content

Instantly share code, notes, and snippets.

@Conaclos
Last active March 28, 2022 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Conaclos/865c86faeeeaab988ac0f753f6e07dad to your computer and use it in GitHub Desktop.
Save Conaclos/865c86faeeeaab988ac0f753f6e07dad to your computer and use it in GitHub Desktop.
SQLite generator of base64 uuid encoded on 96bits (12 octects) in pure SQL

The following SQL statement enables to generate a base64 uuid encoded on 96bits (12 octects).

SELECT (substr(chars, (first & 63)+1, 1) ||
        substr(chars, ((first >> 6) & 63)+1, 1) ||
        substr(chars, ((first >> 12) & 63)+1, 1) ||
        substr(chars, ((first >> 18) & 63)+1, 1) ||
        substr(chars, ((first >> 24) & 63)+1, 1) ||
        substr(chars, ((first >> 30) & 63)+1, 1) ||
        substr(chars, ((first >> 36) & 63)+1, 1) ||
        substr(chars, ((first >> 42) & 63)+1, 1) ||
        substr(chars, (second & 63)+1, 1) ||
        substr(chars, ((second >> 6) & 63)+1, 1) ||
        substr(chars, ((second >> 12) & 63)+1, 1) ||
        substr(chars, ((second >> 18) & 63)+1, 1) ||
        substr(chars, ((second >> 24) & 63)+1, 1) ||
        substr(chars, ((second >> 30) & 63)+1, 1) ||
        substr(chars, ((second >> 36) & 63)+1, 1) ||
        substr(chars, ((second >> 42) & 63)+1, 1)) as uuid
    FROM (
        SELECT 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' as chars,
        random() as first,
        random() as second
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment