Support for Decimal type (Arbitrary Precision Numbers)
See original GitHub issueProblem
The representation of Decimals
and Floats
are fundamentally different. Postgres supports the concept of Arbitrary Precision Numbers via the numeric
/decimal
type.
It would be useful for Prisma to provide a core data type Decimal
to live alongside Float
and Int
in order to support arbitrary precision numbers.
Suggested solution
Since the javascript Number
type does not support arbitrary precision numbers fields with this value could be types as javascript String
types.
Alternatives
Arbitrary precision values can be stored in a String
field, however this prevents filtering/sorting/aggregation. Values could also be stored as a Float
, but this loses the arbitrary precision which is important in many applications. Values could also be stored as Int
, with the decimal shift accounted for manually, but this does not support arbitrary levels of precision in the was a postgres decimal
value does.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:7 (3 by maintainers)
Decimal support was released in the preview of native types: https://www.prisma.io/docs/concepts/components/preview-features/native-types/native-types-mappings#decimal
I think we never posted an update here so here we go.
Client maps any Decimal value to decimal.js object.
As this is implemented, I’ll close this issue.