Best/recommended column type for Id - Drizzle Neon
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
neon supports extensions https://neon.tech/docs/extensions/pg-extensions
you could use pgx_ulid for ULIDs? they're like
01ARZ3NDEKTSV4RRFFQ69G5FAV
i'm using citext for something and adding the create extension statement to a migration and creating a custom column is very easyNeon
Supported Postgres extensions - Neon Docs
Neon supports the Postgres extensions shown in the following table. The supported version of the extension sometimes differs by Postgres version. Extension PG14 PG15 PG16 Notes address_standardizer 3....