hugsql icon indicating copy to clipboard operation
hugsql copied to clipboard

Question: lazy result set

Open jgeraerts opened this issue 7 years ago • 6 comments

With postgresql (probably other databases as well) you can set the fetch-size on a statement to the result set will not be pulled in 1 go into the client. This is useful if you have large result sets you need to process record by record. With plain clojure.java.jdbc you would do that like

(jdbc/with-db-transaction [tx connection]
  (jdbc/query tx
    [(jdbc/prepare-statement (:connection tx)
                              "select * from tablewithmanyrecords"
                              {:fetch-size 10})]
     {:result-set-fn (fn [result-set] ...)}))

https://jdbc.postgresql.org/documentation/94/query.html#query-with-cursor

It's a bit unclear how I would do something similar with hugsql.

jgeraerts avatar May 29 '17 08:05 jgeraerts

+1 does hugsql have any support for cursors?

achikin avatar Jul 20 '17 20:07 achikin

Would also like to know the answer to this question.

tmountain avatar Nov 15 '17 15:11 tmountain

+1

node13h avatar Mar 03 '18 11:03 node13h

+1

si-robinson avatar Sep 20 '19 12:09 si-robinson

Any news on this feature?

ctdean avatar Oct 07 '19 18:10 ctdean

This works for me, given a sqlvec-query and side-effecting-fn to do something with each result.

(jdbc/with-db-transaction [tx *db*]
  (let [results (jdbc/reducible-query tx sqlvec-query {:fetch-size 1000})]
     (transduce (map side-effecting-fn) (constantly nil) results)))

frankleonrose avatar May 27 '21 22:05 frankleonrose