Decimals lose precision (postgres)
See original GitHub issueBug description
The decimals sent to Postgres by the query engine lose precision
How to reproduce
run this script:
import { PrismaClient } from '@prisma/client'
import { Decimal } from '@prisma/client/runtime'
const prisma = new PrismaClient()
const run = async () => {
const value = new Decimal('600.780000000012345678912345678912')
console.log('before', { foo: value })
const foo = await prisma.foo.create({
data: {
amountDecimal: value,
amountString: value.toString(),
},
})
console.log('after', { foo })
}
run()
Expected behaviour
I expect amountDecimal
: 600.7800000006123456789
not 600.7800000006123
,
Prisma information
model Foo {
id String @id @default(uuid())
amountDecimal Decimal @db.Decimal(65, 30)
amountString String
}
SQL Table generated:
CREATE TABLE "Foo" (
"id" TEXT NOT NULL,
"amountDecimal" DECIMAL(65,30) NOT NULL,
"amountString" TEXT NOT NULL,
PRIMARY KEY ("id")
);
Environment & setup
prisma : 2.21.2
@prisma/client : 2.21.2
Current platform : darwin
Query Engine : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio : 0.371.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
PostgreSQL real type losing integer precision when printed ...
The problem seems to originate from the way PHP returns results. The values are not returned as the corresponding data type, ...
Read more >decimal lose precision digits to postgres · Issue #8160 - GitHub
MySQL DECIMAL(X, 5) returns incorrect precision. #13156 ; Decimals lose precision (postgres) #6852 ; [PostgreSQL] Cannot create or update row with large Decimal ......
Read more >How to prevent PostgreSQL from automatically rounding ...
In this case, I have lost precision. I entered five decimal places, but Postgres automatically rounded down to four.
Read more >Documentation: 9.3: Numeric Types - PostgreSQL
Numeric types consist of two-, four-, and eight-byte integers, four- and eight-byte floating-point numbers, and selectable-precision decimals.
Read more >PostgreSQL Data Types - Numeric, Text, and More - Prisma
Specify precision followed by scale when configuring a column using both controls. PostgreSQL will round the decimal component of any input to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’ll be tackling this in #6902
For internal bookkeeping: This was considered a duplicate of https://github.com/prisma/prisma/issues/5925