Handle :nulls-first and :nulls-last in order-by
This commit implements NULLS (FIRST | LAST) in ORDER BY clause, as introduced by SQL:2003, link to grammar specification: http://savage.net.au/SQL/sql-2003-2.bnf.html#sort%20specification%20list Only PostgreSQL 8.4+ and Oracle 10+ support said feature as of currently.
This commit is contained in:
parent
7160b4b1ad
commit
500b55775e
1 changed files with 10 additions and 9 deletions
|
|
@ -412,15 +412,16 @@
|
||||||
(str "ORDER BY "
|
(str "ORDER BY "
|
||||||
(comma-join (for [field fields]
|
(comma-join (for [field fields]
|
||||||
(if (sequential? field)
|
(if (sequential? field)
|
||||||
(let [[field order & [nulls-order]] field]
|
(let [[field & modifiers] field]
|
||||||
;; Correct way of handling this would be to
|
(string/join " "
|
||||||
;; expect a dictionary with either order,
|
(cons (to-sql field)
|
||||||
;; nulls order or both at the same
|
(for [modifier modifiers]
|
||||||
;; time. However, so far I'm not sure how to
|
(case modifier
|
||||||
;; achieve that, so first iteration will have
|
:desc "DESC"
|
||||||
;; to use dirty hacks.
|
:asc "ASC"
|
||||||
(str (to-sql field) " " (if (= :desc order)
|
:nulls-first "NULLS FIRST"
|
||||||
"DESC" "ASC")))
|
:nulls-last "NULLS LAST"
|
||||||
|
"")))))
|
||||||
(to-sql field))))))
|
(to-sql field))))))
|
||||||
|
|
||||||
(defmethod format-clause :limit [[_ limit] _]
|
(defmethod format-clause :limit [[_ limit] _]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue