drizzle-orm
drizzle-orm copied to clipboard
[BUG]: numeric types returning type string with postgres
What version of drizzle-orm
are you using?
0.25.3
What version of drizzle-kit
are you using?
0.17.6
Describe the Bug
export const order = pgTable(
'orders', {
...
totalValue: numeric('total_value', { precision: 10, scale: 2 }),
...
})
inspecting order.totalValue
I get type
PgNumeric<{
tableName: "orders";
name: "total_value";
data: string;
driverParam: string;
notNull: false;
hasDefault: false;
}>
but when I do a query such as
await db
.insert(order)
.values({
...input,
})
.returning(defaultSelect);
The result is inferred as string | null
for this column
Expected behavior
I would expect returning to be number | null
Environment & setup
Node : 16.17.1 OS : win32 x64 pnpm : 8.1.0
Trying to work around this I also have to convert a comparison value to string to compare in queries, e.g.
query.where(gte(orderTable.total_value, someValue.toString()))
Hey I'd like to start contributing towards the project. Can I take this up?
As @bestickley mentioned here https://github.com/drizzle-team/drizzle-orm/pull/745#issuecomment-1589804662 we use numeric as string to have the same precision as database has