-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
After some research it turns out this is supposedly intended by node/pg, it casts the numbers as strings for precision.
Would be nice to include this information in the docs, as has apparently been requested numerous times for months now.
IE: #1042 - Closure without acknowledgement of suggestion, which is tripping up a lot of people.
Report hasn't been filed before.
- I have verified that the bug I'm about to report hasn't been filed before.
What version of
drizzle-ormare you using?0.39.1
What version of
drizzle-kitare you using?0.30.4
Other packages
No response
Describe the Bug
To fill this field, please answer the following:
Undesired behaviour:
- Throwing a type error when attempting to insert numbers into a numeric() or decimal() column.
What are the steps to reproduce it?
- Schema:
export const watchedCoins = pgTable("watched_coins", { id: serial("id").primaryKey(), coinId: integer("coin_id").notNull(), startValue: decimal("start_value", { precision: 100, scale: 30 }).notNull(), thresholdValue: decimal("threshold_value", { precision: 100, scale: 30 }).notNull(), createdAt: timestamp("created_at") .default(sql`CURRENT_TIMESTAMP`) .notNull(), updatedAt: timestamp("updated_at").$onUpdate(() => new Date()), });
Insert:
await db.insert(watchedCoins).values({ coinId: 5, startValue: 5, thresholdValue: 5 });The operation will run fine, but you've got an annoying cryptic type error (which doesn't even underline the right part):
When verifying with the following, hovering over startValue & thresholdValue will state that your numeric or decimal column expects a string.
const test: typeof watchedCoins.$inferInsert = { coinId: 5, startValue: 10, thresholdValue: 15, };What is the desired result?
Don't expect a string out of numeric & decimal alias. It takes in a number.

