Fixes #248 by changing how aliases are rendered

In theory, the only change here will be to stop the paren-wrapping in 
generation of alias SQL -- but I think that treating alias/columns pairs 
like this (as a nested alias) is very suspicious anyway so that probably 
ought to be fixed "properly" at some point.
This commit is contained in:
Sean Corfield 2019-09-05 16:38:20 -07:00
parent f594235444
commit 94601ee5ae
3 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,7 @@
## Changes coming in 0.9.7
* Fix #248 by treating alias as "not a subquery" when generating SQL for it. (@seancorfield)
## 0.9.6
* Filter `nil` conditions out of `where`/`merge-where`. Fix #246. (@seancorfield)

View file

@ -368,7 +368,8 @@
(if (= :select *clause*) " AS " " ")
(if (or (string? alias) (keyword? alias) (symbol? alias))
(quote-identifier alias :split false)
(to-sql alias)))))))
(binding [*subquery?* false]
(to-sql alias))))))))
(extend-protocol types/Inlinable
#?(:clj clojure.lang.Keyword

View file

@ -46,6 +46,10 @@
:quoting :mysql))
"aliases containing \".\" are quoted as necessary but not split"))
(deftest values-alias
(is (= ["SELECT vals.a FROM (VALUES (?, ?, ?)) vals (a, b, c)" 1 2 3]
(format {:select [:vals.a]
:from [[{:values [[1 2 3]]} [:vals {:columns [:a :b :c]}]]]}))))
(deftest test-cte
(is (= (format-clause
(first {:with [[:query {:select [:foo] :from [:bar]}]]}) nil)