Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1081079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:07:15+00:00 2026-05-16T22:07:15+00:00

The clojure.contrib.sql library returns BigDecimals for all numeric fields. What’s a good way to

  • 0

The clojure.contrib.sql library returns BigDecimals for all numeric fields. What’s a good way to have some fields as Integers? Example code below:

(sql/with-connection my-db 
   (sql/with-query-results res 
      [sql-str 6722] 
      (into [] res)))

In the resulting collection of records all numbers are BigDecimal. Some of these are foreign keys, and for reasons of my own, I need them to be integer.

I know I can iterate over the collection and convert them, but I would rather not do this as it is a very large collection, and it seems right to have the library use ResultsSet.getInteger if the number fits into an integer.

The DB is Oracle, and the integer DB fields are defined as NUMBER(10)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:07:15+00:00Added an answer on May 16, 2026 at 10:07 pm

    As atreyu noted, a 10-digit integer won’t necessarily fit within an Integer.

    More importantly, the seq you are given is created by clojure.core/resultset-seq, which in turn is calling ResultSet.getObject(int). As per the JDBC spec, the BigDecimals are being returned because that’s the java type that corresponds to the column’s SQL type.

    Also, you don’t need to worry about “iterat[ing] over the collection”. The resultset-seq is lazy, and map is lazy, so you’ll just end up converting each number right before you consume them. E.g.,

    (sql/with-connection my-db 
       (sql/with-query-results res 
          [sql-str 6722] 
          (do-stuff 
             (map (comp int :id) res))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble doing anything with clojure.contrib.sql beyond establishing a connection. I have a
I have a function to get JDBC metadata through clojure-sql (ns relink (:require [clojure.contrib.sql
(ns db-example (:use [clojure.contrib.sql :only (with-connection with-query-results)] ) (:import (java.sql DriverManager))) ;; need this
In Clojure, what would be the nicest way to have a sliding window over
I have a sql exception from clojure that goes like this: java.lang.Exception: transaction rolled
Clojures clojure.xml/parse, clojure.zip/xml-zip and clojure.contrib.zip-filter.xml/xml-> are excellent tools for pulling values out of xml,
One of my project.clj's :dependencies is dependent on the monolithic clojure-contrib-1.1.0.jar, but I can't
clojure-xml/parse returns a map of an xml file. (ns xml-lib.core ^{:author Charles M. Norton,
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.