This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-10
Channels
- # announcements (1)
- # babashka (16)
- # beginners (42)
- # calva (6)
- # clj-kondo (7)
- # clj-yaml (13)
- # cljdoc (7)
- # clojure (34)
- # clojure-bay-area (7)
- # clojure-dev (14)
- # clojure-europe (10)
- # clojure-nl (1)
- # clojure-norway (26)
- # clojure-sweden (91)
- # clojurescript (7)
- # datalevin (3)
- # datomic (35)
- # dev-tooling (8)
- # emacs (22)
- # graphql (1)
- # honeysql (13)
- # hyperfiddle (28)
- # introduce-yourself (1)
- # jobs-discuss (11)
- # juxt (4)
- # lsp (21)
- # off-topic (7)
- # reagent (4)
- # releases (3)
- # spacemacs (16)
- # xtdb (4)
- # yamlscript (2)
Hello there, XTDB noob here. I’m having a problem with the following attempt at date comparison: Is it the nested function call or something else? The XTDB docs don’t say that about predicates but transformation functions. Also, what would be the best way to compare dates? Is there a date data type that works better in this situation? Thanks PS: The date values are just for testing the query. In real usage, it will be other values.
'{:find [(pull e [*])]
:where [
[(= (clojure.core/compare (java.time.LocalDateTime/now) (java.time.LocalDateTime/of 2018 1 1)) -1 )]
]}
Hey @U9FEN7GF6 🙂 so firstly you can't use arbitrary Clojure expressions in the middle of Datalog, instead you are limited to only the top-level of parens being interpreted as a function call. In this case that function is =
, and the (clojure.core/compare ...
is being interpreted as a list of symbols rather than a nested expression. To work around this you can use intermediate clauses that introduce new logic variables, e.g. [(java.time.LocalDateTime/now) now] [(= now -1)]
As for date types, XT uses Date
internally quite heavily but other types are natively supported within the sorted indexes, including LocalDateTime - specifically: https://github.com/xtdb/xtdb/blob/29fa08b921e0809f37469cbb40972daa4b88851c/core/src/xtdb/codec.clj#L96-L100
I couldn't personally say that any date type is 'better', although I would tend to stick with Date
until I had reasons to use anything else, purely because I understand it the best 😅
Also note that clojure.core/compare
should be available as compare
(i.e. without the ns component, along with everything else under clojure.core/*
) when used in the function position at the top-level of a clause, but if there's ever a chance of clashing symbols then it doesn't hurt to be verbose ☺️