Next.js Discord

Discord Forum

Should I use numeric or int4 in postgres?

Unanswered
Anay-208 posted this in #help-forum
Open in Discord
Avatar
So I faced a error where the data type returned was being numeric.
-# 0-init.tsx
    .addColumn("balance", "numeric(10, 2)", (col) => col.notNull())


I researched about it, and found out there is pg.types

However, I can't use it because I'm using neon serverless driver

The cause of the issue was, the size of int was too high, which JS doesn't support(only supports via bigint), and even if size is decreased, it'd still return NUMERIC & DECIMAL types in string.
https://www.postgresql.org/docs/current/datatype-numeric.html

I'm currently finding 2 approaches to this issue:
- parseDouble manually in code
- Store in int4, and divide by 100 every time.

I'm pretty sure there are pros & cons of both, so I'm unsure which option to pick.

1 Reply

Avatar
bump