Fork me on GitHub

Hi. I'm trying to figure out a way to get the containment operator from Postgres registered with honeysql in a good way. The @> operator does not easily represent as a keyword in clojure because of the @ character.


So while I could do (honey.sql/register-op! (keyword "@>")), I would then have to refer to the operator via (keyword "@>") everywhere I want to use it. 😕


@snorremd I would just define a global somewhere with an mnemonic name for it:

(def at> (keyword "@>"))
(sql/register-op! at>)
(sql/format ... at> ...)


(given Clojure's restrictions on using @ there's really not much else you can do -- this applies to a number of PostgreSQL "enhancements" that use weird characters)


Thanks! Did not think about just defining a global. I made a function instead with infix notation:

(defn- contains-formatter [_f args]
  (let [[sql & params] (hsql/format-expr-list args)]
    (into [(str (first sql) " @> " (second sql))]
          (flatten params))))

(hsql/register-fn! :at> contains-formatter)
This seems to work reasonably well, but yours is simpler. 🙂