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 "
|
||||
(comma-join (for [field fields]
|
||||
(if (sequential? field)
|
||||
(let [[field order & [nulls-order]] field]
|
||||
;; Correct way of handling this would be to
|
||||
;; expect a dictionary with either order,
|
||||
;; nulls order or both at the same
|
||||
;; time. However, so far I'm not sure how to
|
||||
;; achieve that, so first iteration will have
|
||||
;; to use dirty hacks.
|
||||
(str (to-sql field) " " (if (= :desc order)
|
||||
"DESC" "ASC")))
|
||||
(let [[field & modifiers] field]
|
||||
(string/join " "
|
||||
(cons (to-sql field)
|
||||
(for [modifier modifiers]
|
||||
(case modifier
|
||||
:desc "DESC"
|
||||
:asc "ASC"
|
||||
:nulls-first "NULLS FIRST"
|
||||
:nulls-last "NULLS LAST"
|
||||
"")))))
|
||||
(to-sql field))))))
|
||||
|
||||
(defmethod format-clause :limit [[_ limit] _]
|
||||
|
|
|
|||
Loading…
Reference in a new issue