YouTube-Like Short IDs as Postgres Primary Keys(github.com)
github.com
YouTube-Like Short IDs as Postgres Primary Keys
https://github.com/turbo/pg-shortkey
3 コメント
TBF there's only a 50% chance that the deduplication loop will run (once) after 5.1 x 10^9 keys. It's still better than erroring in that case IMO.
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().
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().
Alternatively, perhaps one could handle the duplicate key error on an insert into the table using one of these keys as the PK.
I never did the deduplication query thing though - using 11 base58 digits seemed good enough for that app.