簡體   English   中英

PostgreSQL數字類型和Play的anorm解析器! 斯卡拉2.3

[英]PostgreSQL numeric type and anorm parser with Play! scala 2.3

我想使用Postgresql 9.3的數字類型,但是我的解析器是:

private val Account403Parser: RowParser[Account403] = {
  get[Long]("id") ~
  get[Float]("amount") map {
  case id ~ amount =>
    Account403.apply(id, amount)
}

無法正常運行,因為主動脈無法從java.math.BigDecimal轉換為Float。

這是我得到的錯誤:

[RuntimeException: TypeDoesNotMatch(Cannot convert 9.5: class java.math.BigDecimal to Float for column ColumnName(account403.amount,Some(amount)))]

如何更改解析器以使其從java.math.BigDecimal類型轉換為Float類型?

根據文檔中類型兼容性矩陣,應使用

BigDecimalDoubleLong來分配BigDecimal

或者,您可以在Postgres端將其強制轉換為real (4字節浮點數): amount::real ,從而失去一些精度。 不確定scala中的語法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM