You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A table with a column of type numeric[] that is defined as column[List[Double]] will insert List[Double] for that column just fine. However, it will not read a List[Double] but a List[BigDecimal] at runtime.
This will result in a ClassCastException when trying to access the values of List[Double]: ERROR: java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Double (java.math.BigDecimal and java.lang.Double are in module java.base of loader 'bootstrap')
createtabletest
(
id serialprimary key,
test numeric[]
);
caseclassTest(test: List[Double]) //the field test will be read as List[BigDecimal]defid= column[Int]("id", O.PrimaryKey, O.AutoInc)
deftest= column[List[Double]]("test")
def*=
(
id.?::
test::HNil
).<>(applyTest, unapplyTest)
defapplyTest(data: Option[Int] ::List[Double] ::HNil):Test= data match {
data match {
case _ :: list =>Test(list)
}
}
VPostgresProfile.api._ and VPostgresProfile is in scope:
defapplyTest(data: Option[Int] ::List[Double] ::HNil):Test= data match {
data match {
case _ :: list =>Test(list.asInstanceOf[List[java.math.BigDecimal]].map(_.doubleValue))
}
The text was updated successfully, but these errors were encountered:
@TobiasPfeifernumeric[] was bind to List[BigDecimal], and float8[] was bind to List[Double].
But pg can accept double[] to numeric[], so the insert with List[Double] is ok.
You can change the declaration of test numeric[] to test float8[], to keep them consistent.
I had the same issue. When I want to use BigDecimal instead, I get the following compile error:
could not find implicit value for parameter tt: slick.ast.TypedType[Option[List[BigDecimal]]]
def valueNumericArray = column[Option[List[BigDecimal]]]("value_numeric_array")
slick-pg version: 0.20.3
slick version: 3.3.3
A table with a column of type
numeric[]
that is defined ascolumn[List[Double]]
will insertList[Double]
for that column just fine. However, it will not read aList[Double]
but aList[BigDecimal]
at runtime.This will result in a
ClassCastException
when trying to access the values ofList[Double]
:ERROR: java.lang.ClassCastException: class java.math.BigDecimal cannot be cast to class java.lang.Double (java.math.BigDecimal and java.lang.Double are in module java.base of loader 'bootstrap')
VPostgresProfile.api._
andVPostgresProfile
is in scope:workaround:
The text was updated successfully, but these errors were encountered: