korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Timestamp search #228

Closed mogverse closed 9 years ago

mogverse commented 10 years ago

How does one search for timestamp >= starttime and timestamp <= endtime. I am using postgres and on using {:timestamp [<= starttime]} it is expecting starttime to be an integer. timestamp is a datetime with timezone field in postgres and starttime time is java.sql.timestamp.

immoh commented 10 years ago

I just tested this with Postgres and it seems to work fine with timestamp with time zone and java.sql.Timestamp. Can you post more details about your implementation and error message?

nvbn commented 10 years ago

Have same issue with code:

(-> (k/select* m/items)
    (k/where* {:date_taken [> (to-sql-tiem (now))]})
    k/exec)

Wtih error:

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Number
         Numbers.java:227 clojure.lang.Numbers.gt
            core.clj:1036 clojure.core/>
           engine.clj:217 korma.sql.engine/pred-vec
            core.clj:2559 clojure.core/map[fn]
          LazySeq.java:40 clojure.lang.LazySeq.sval
          LazySeq.java:49 clojure.lang.LazySeq.seq
              RT.java:484 clojure.lang.RT.seq
             core.clj:133 clojure.core/seq
            core.clj:2855 clojure.core/dorun
            core.clj:2871 clojure.core/doall
           engine.clj:222 korma.sql.engine/pred-map
            engine.clj:57 korma.sql.engine/map-val
           engine.clj:334 korma.sql.engine/sql-where-or-having[fn]
            core.clj:2557 clojure.core/map[fn]
          LazySeq.java:40 clojure.lang.LazySeq.sval
          LazySeq.java:49 clojure.lang.LazySeq.seq
          LazySeq.java:71 clojure.lang.LazySeq.first
              RT.java:577 clojure.lang.RT.first
              core.clj:55 clojure.core/first
           string.clj:185 clojure.string/join
           engine.clj:336 korma.sql.engine/sql-where-or-having
             AFn.java:160 clojure.lang.AFn.applyToHelper
             AFn.java:144 clojure.lang.AFn.applyTo
             core.clj:628 clojure.core/apply
            core.clj:2470 clojure.core/partial[fn]
          RestFn.java:408 clojure.lang.RestFn.invoke
           engine.clj:397 korma.sql.engine/->sql
             core.clj:465 korma.core/exec[fn]
             core.clj:465 korma.core/exec

Same time insert and update with (to-sql-time (now)) works ok.

nvbn commented 10 years ago

Found solution in #52. With:

(-> (k/select* m/items)
    (k/where* {:date_taken ['> (to-sql-tiem (now))]})
    k/exec)

all works.