drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: numeric types returning type string with postgres

Open AdditionAddict opened this issue 1 year ago • 2 comments

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

AdditionAddict avatar May 11 '23 10:05 AdditionAddict

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()))

AdditionAddict avatar May 16 '23 07:05 AdditionAddict

Hey I'd like to start contributing towards the project. Can I take this up?

fanatic75 avatar May 22 '23 07:05 fanatic75

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

AndriiSherman avatar Jul 21 '23 17:07 AndriiSherman