N
Neon2y ago
xenial-black

Best column type for id field - Drizzle

Hi everyone. I am using Drizzle, Next.js 14 app router & Neon serverless. Could anyone help me sharing the best column type for id field in a table? I think a solution that is auto generating, random, yet not very large (like UUID) is best. Most tutorials show a type of either text or serial. But text does not automatically set the Id, so I can't use insert without providing an id field. Serial is auto incrementing, but I read that such auto incrementing id is bad for security (ids being predictable). UUID is another option but they take up a lot of space & have some other downsides (https://dev.to/harshhhdev/uuidguid-cuid-nanoid-whats-the-difference-5dj1) . So which one should I use? I would love if you could share a short example with your answer. Thank you.
1 Reply
rival-black
rival-black2y ago
if you are going to expose IDs in your client application, use a UUID UUID v7 I think is supposed to help UUIDs be laid out better in a btree index

Did you find this page helpful?