ErrorsReads and writes · rule
data.stored_decimal_scale
Update by id adds a decimal with more places than its field keeps.
Area 6, Reads and writes; not declinable; the next step is usually the agent's.
The database rounds a sum its own way, so a decimal added to a stored field keeps no more places than the field does:
type Balance = Decimal { scale: 2}entity Wallet { id: Uuid balance: Balance}action add_interest(wallet_id: Wallet.id) fails WalletNotFound -> Wallet { return attempt Wallet.update(wallet_id) { set: { balance: Balance(Wallet.balance + 0.005) } }}
error Wallet.update adds a decimal with more places than Wallet.balance keeps
--> main.jadpo:13:47
|13 | balance: Balance(Wallet.balance + 0.005) | ^^^^^ 3 decimal places
- reason
- The database works
Wallet.balanceout in one step, and keeps it atscale: 2;0.005has 3, and PostgreSQL would round the result half away from zero where Jadpo rounds half to even, so the stored value could differ from Jadpo's. - next
- Give the value at most 2 decimal places, or a type with
scale: 2or fewer (agent) - rule
- data.
stored_ decimal_ scale - help
- https://jadpo.
dev/docs/errors/data. stored_ decimal_ scale
Markdown for agents: /docs/errors/data.stored_decimal_scale.md.Built from Jadpo main at aee2e8f.