YouTube-Like Short IDs as Postgres Primary Keys
github.com
github.com
I never did the deduplication query thing though - using 11 base58 digits seemed good enough for that app.
If that's not needed, the loop and subquery and be removed. This then enables the usage of shortkey_generate() as a DEFAULT expression instead of a trigger. Maybe I should provide that as an alternative, something like shortkey_generate_unsafe().