Skip to content

Problem with Db.runQuery and NUMERIC results #36

Closed
jeppenejsum opened this Issue Jul 22, 2009 · 5 comments

4 participants

@jeppenejsum
Lift Web Framework member

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

@dpp
Lift Web Framework member
dpp commented Aug 25, 2009

Special treatment for NUMERIC and DECIMAL closed by 9a592cd94f24c4eb2a7f443d227dd7f28741be74

@dchenbecker
Lift Web Framework member

I'll check in this fix to 1.0.1 shortly.

@dchenbecker
Lift Web Framework member

Checked in and deploying now.

@dpp dpp was assigned Mar 1, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.