Search code examples
postgresqlclojurekorma

How to make where clause with comparing two fields in SqlKorma (clojure)


I'm using Postgresql and sqlkorma 0.4.

CREATE TABLE mytable (id serial PRIMARY KEY, 
   a integer NOT NULL, b integer NOT NULL);

How to make:

SELECT * FROM mytable WHERE a > b

I've tried

(defentity mytable
       (pk :id)
       (table :mytable))

and

(select table mytable
  (fields :a :b)
  (where (> a b)))

but it doesn't work.


Solution

  • (sql-only
      (select my-table (where {:a [> :b]})))
    ;; => "SELECT `my-table`.* FROM `my-table` WHERE (`my-table`.`a` > `my-table`.`b`)"