我想將高價值貨幣值存盤到資料庫中。
我嘗試integer在遷移中使用一個欄位,但是出現以下錯誤
PG::NumericValueOutOfRange: ERROR: numeric field overflow
DETAIL: A field with precision 8, scale 2 must round to an absolute value less than 10^6.
所以我然后嘗試精確地使用十進制
t.decimal :value, precision: 30, scale: 2
一旦獲得,當我進入時我會遇到同樣的錯誤
我想知道的是,是否有可能,以及如何將類似的值保存1000000.0到資料庫中。
uj5u.com熱心網友回復:
我嘗試在遷移中使用整數欄位,但是出現以下錯誤
PG::NumericValueOutOfRange: ERROR: numeric field overflow DETAIL: A field with precision 8, scale 2 must round to an absolute value less than 10^6.
那是一種誤解。錯誤訊息是針對資料型別的numeric——numeric(8,2)準確地說——不是integer。
解決方案
只需在numeric沒有精度和規模的情況下使用。它完全按照給定的方式存盤十進制數(帶有任意數量的小數位數)。
decimal是numericPostgres 中的同義詞。
如果您沒有小數位數,請考慮integer(max 2^31 - 1) 或bigint(max 2^63 - 1)。
有關的:
- PostgreSQL:貨幣應使用哪種資料型別?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/341490.html
上一篇:Swift/Vapor中的Postgresjsonb資料
下一篇:獲取客戶年初至今的支出
