Added support for casts of the form CAST(foo AS type)
This commit is contained in:
parent
0c3f3d0403
commit
dd9647ee3e
2 changed files with 11 additions and 0 deletions
|
|
@ -99,6 +99,11 @@
|
||||||
(defmethod fn-handler "distinct-on" [_ & args]
|
(defmethod fn-handler "distinct-on" [_ & args]
|
||||||
(str "DISTINCT ON (" (comma-join (map to-sql args)) ")"))
|
(str "DISTINCT ON (" (comma-join (map to-sql args)) ")"))
|
||||||
|
|
||||||
|
(defmethod fn-handler "cast" [_ field cast-to-type]
|
||||||
|
(str "CAST" (paren-wrap (str (to-sql field)
|
||||||
|
" AS "
|
||||||
|
(to-sql cast-to-type)))))
|
||||||
|
|
||||||
(defmethod fn-handler "=" [_ a b & more]
|
(defmethod fn-handler "=" [_ a b & more]
|
||||||
(if (seq more)
|
(if (seq more)
|
||||||
(apply expand-binary-ops "=" a b more)
|
(apply expand-binary-ops "=" a b more)
|
||||||
|
|
|
||||||
|
|
@ -55,3 +55,9 @@
|
||||||
"bort" "gabba" 2])))
|
"bort" "gabba" 2])))
|
||||||
(testing "SQL data prints and reads correctly"
|
(testing "SQL data prints and reads correctly"
|
||||||
(is (= m1 (read-string (pr-str m1)))))))
|
(is (= m1 (read-string (pr-str m1)))))))
|
||||||
|
|
||||||
|
(deftest test-cast
|
||||||
|
(is (= ["SELECT foo, CAST(bar AS integer)"]
|
||||||
|
(sql/format {:select [:foo (sql/call :cast :bar :integer)]})))
|
||||||
|
(is (= ["SELECT foo, CAST(bar AS integer)"]
|
||||||
|
(sql/format {:select [:foo (sql/call :cast :bar 'integer)]}))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue