5

How would I use clojureql to select between two dates? Hopefully something like this:

@(-> (table :abc)
     (select (where (between d1 d2))))
Kevin
  • 24,871
  • 19
  • 102
  • 158

2 Answers2

6

You can write your own between

(defmacro between
  [x min max]
  `(and (< ~min ~x) (< ~x ~max)))

This will be compatible with ClojureQL.

John Cromartie
  • 4,184
  • 27
  • 32
4

There is no BETWEEN, and while you might be tempted to use Lisp-y multiple-argument <, that does not work either:

;; invalid SQL output
hello-cql.core> (select (table :abc) (where (< 10 :a 20)))
SELECT abc.* FROM abc WHERE (10 < a < 20)

;; valid SQL output
hello-cql.core> (select (table :abc) (where (and (< 10 :a) (< :a 20))))
SELECT abc.* FROM abc WHERE ((10 < a) AND (a < 20))
michel-slm
  • 9,438
  • 3
  • 32
  • 31