I opted to use CUID(2)s for various reasons but I’m having trouble to get this to fully work in my PostgreSQL database that I’ve hosted on DigitalOcean.
While it works perfectly when I generate them via Prisma, I can’t find a fully working solution when I need to generate them within the database itself, for instance when using a trigger to generate an audit log for certain tables.
There’s a very useful extension that lets you generate various kinds of IDs but it is not supported and I’m not getting my hopes up that it will be any time soon.
I’ve added this function to my database which can generate them but it recommends using a unique value for every server that I’m unable to set.
This is done via
SET plpgsql.cuid_hostid = "XXXXXX"; -- for instance 897892. This exact command will fail because plpgsql is a reserved prefix. Using any other prefix works during a session but will fail as soon as the session is terminated.
I can get it to work by omitting this but I fear that this might cause trouble down the line.
My question is: How do I set a server constant like this that will stay set for as long as the server exists?
Also: Why are CUIDs not treated as equals to BigInt and UUIDs?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.