Fork me on GitHub
#sql
<
2022-11-25
>
Adam Kalisz10:11:34

Hi. I use next.jdbc with PostgreSQL and I sum up a bigint column (but it does the same even for an integer column). It seems, the result in somehow converted to java.math.BigDecimal instead of just being java.lang.Long. The number is not very large either, well withing limits of Long. Has anybody encountered this problem?

Adam Kalisz10:11:02

This seems to explain some of it. https://stackoverflow.com/questions/58640603/clojure-jdbc-weird-response-for-sum Do I really get numeric that is then converted to BigDecimal no matter what?

Adam Kalisz11:11:47

Ok, I have found a solution. Basically, sum of bigint is always numeric even when it is not needed (the result isn't out of range of bigint). If you can guarantee the result is in the bigint domain, you can safely cast the result.

seancorfield20:11:25

This is how JDBC works. Nothing to do with next.jdbc (or clojure.java.jdbc). You get whatever default (Java) type the JDBC driver thinks is appropriate for the SQL data type for that column.