Allow with expr AS ident syntax in WITH clause
This commit is contained in:
parent
e553f4f169
commit
30e554f31c
1 changed files with 19 additions and 9 deletions
|
|
@ -159,6 +159,11 @@
|
|||
[]
|
||||
(= :sqlserver (:dialect *dialect*)))
|
||||
|
||||
(defn- clickhouse?
|
||||
"Helper to detect if Clickhouse is the current dialect."
|
||||
[]
|
||||
(= :clickhouse (:dialect *dialect*)))
|
||||
|
||||
;; String.toUpperCase() or `str/upper-case` for that matter converts the
|
||||
;; string to uppercase for the DEFAULT LOCALE. Normally this does what you'd
|
||||
;; expect but things like `inner join` get converted to `İNNER JOİN` (dot over
|
||||
|
|
@ -555,9 +560,14 @@
|
|||
(map
|
||||
(fn [[x expr :as with]]
|
||||
(let [[sql & params] (format-with-part x)
|
||||
[sql' & params'] (format-dsl expr)]
|
||||
[sql' & params'] (if (and (clickhouse?) ;;in clickhouse the expression can be
|
||||
(not (map? expr))) ;; a string arranged as `with expr as ident`
|
||||
(format-expr expr)
|
||||
(format-dsl expr))]
|
||||
;; according to docs, CTE should _always_ be wrapped:
|
||||
(cond-> [(str sql " " (as-fn with) " " (str "(" sql' ")"))]
|
||||
(cond-> [(if (and (clickhouse?) (not (map? expr)))
|
||||
(str sql' " AS " sql)
|
||||
(str sql " " (as-fn with) " " (str "(" sql' ")")))]
|
||||
params (into params)
|
||||
params' (into params'))))
|
||||
xs))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue