Using increment on Decimal fields?

In the docs, it explicitly mentions atomic number operations like increment, decrement etc. only works on Float and Int. https://www.prisma.io/docs/orm/reference/prisma-client-reference#atomic-number-operations However, I tried it on a Decimal field, and it seems to work fine. Does that mean I can use it without any issues? Or are there any issues that could pop up? Part of my schema:
model Pot {
id String @id @default(cuid())
currentAmount Decimal @default(0.00) @db.Decimal(12, 2)
}
model Pot {
id String @id @default(cuid())
currentAmount Decimal @default(0.00) @db.Decimal(12, 2)
}
Query:
await prisma.pot.update({
where: { userId, potId },
data: { currentAmount: { increment: amountToUpdate } },
})
await prisma.pot.update({
where: { userId, potId },
data: { currentAmount: { increment: amountToUpdate } },
})
amountToUpdate is a string.
4 Replies
Prisma AI Help
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurul3w ago
The precision can be lost in some cases: https://github.com/prisma/prisma/issues/18581
GitHub
Increment/decrement loses precision with decimal columns · Issue #...
Discussed in #18518 Originally posted by drishit96 March 27, 2023 I am trying to increment a column of type Decimal @db.Decimal(22, 4). It works for numbers which are supported by the number primit...
Darkstar
DarkstarOP3w ago
Thanks! Yeah, I saw this issue on GH after creating this thread. I think it should be fine for my case, I won't have that many big numbers or lot of decimal points.
Nurul
Nurul3w ago
Sounds good! 👍

Did you find this page helpful?