Recommended column type for id field - Drizzle pg

95 views Asked by At

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. So which one should I use?

I would love if you could share a short example with your answer. Thank you.

I tried serial field but it is predictable & less secure. I tried UUID but it is too long. I need random short auto generating Id field.

0

There are 0 answers