Problem with Db.runQuery and NUMERIC results
I'm using adhoc queries and I'm running into a problem where the results
of aggregate functions get mapped to integers:
I have this
val (_,result) = DB.runQuery("SELECT AVG(vt.fuel_efficiency), vt.fuel_type, vt.category FROM "+
"vehicles v JOIN vehicle_types vt ON v.vehicle_type_id= vt.id "+
"WHERE v.account_id=? "+
"GROUP BY vt.fuel_type, vt.category "+
"ORDER BY vt.fuel_type, vt.category",
List(User.currentUser.open_!.account.is))
in Postgres, the first column is returned as NUMERIC, ie with decimals, but in
private def asString(pos: Int, rs: ResultSet, md: ResultSetMetaData)
we have this:
case BIGINT | INTEGER | DECIMAL | NUMERIC | SMALLINT | TINYINT =>
rs.getLong(pos).toString
which seems wrong.
>
> So... numeric should be rs.getDouble(pos).toString ?
Yes, or BigDecimal. Same goes for DECIMAL I think. "The recommended Java
mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal" [1]
[1] http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.html
of aggregate functions get mapped to integers:
I have this
val (_,result) = DB.runQuery("SELECT AVG(vt.fuel_efficiency), vt.fuel_type, vt.category FROM "+
"vehicles v JOIN vehicle_types vt ON v.vehicle_type_id= vt.id "+
"WHERE v.account_id=? "+
"GROUP BY vt.fuel_type, vt.category "+
"ORDER BY vt.fuel_type, vt.category",
List(User.currentUser.open_!.account.is))
in Postgres, the first column is returned as NUMERIC, ie with decimals, but in
private def asString(pos: Int, rs: ResultSet, md: ResultSetMetaData)
we have this:
case BIGINT | INTEGER | DECIMAL | NUMERIC | SMALLINT | TINYINT =>
rs.getLong(pos).toString
which seems wrong.
>
> So... numeric should be rs.getDouble(pos).toString ?
Yes, or BigDecimal. Same goes for DECIMAL I think. "The recommended Java
mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal" [1]
[1] http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.html
Leave a comment
on 2010-02-06 19:47 *
By github.importer
Imported from GitHub: http://github.com/dpp/liftweb/issues/36/find