-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]:Expect to return type number but got string #3116
Comments
@gauravterrascope This is not a bug. |
If you actually want a float, then |
Just to confirm, if my field is to input a let's say a salary, i should store them as Decimal in database, but i should define this type as a "string" in my validation schema (e.g. Zod)? |
Yes, because numeric and decimal fields are strings in the database and should stay that way. When you use createInsertSchema, these fields are defined as strings by default. Depending on your use case, you might also want to store a salary as the smallest currency amount. For example, 500 to resemble $5. Then you can safely use an integer. But this is only feasible if you are working with a single currency and do not need fractional cents. If an accountant or HR is involved, it is best to check for possible requirements for decimal places. |
Just dropping a note here to thank @dennismuench this was very helpful. Might be worth putting a little footnote or something in the docs just pointing to either this issue or something as I was looking for the same answer :) |
Closing this issue. |
What version of
drizzle-orm
are you using?0.34.1
What version of
drizzle-kit
are you using?0.25.0
Describe the Bug
The
$inferInsert
returns the type as string for keys which are numeric or floats in drizzle pgTable schemaSteps to reproduce
Expected behavior
Here property age should be number in typescript
Environment & setup
Node 18
Macbook M1 pro
The text was updated successfully, but these errors were encountered: