LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
284 stars 39 forks source link

Problem with Union queries #93

Closed ariel123 closed 12 years ago

ariel123 commented 13 years ago

The following query doesn't generate correct sql:

(-> (sq/select (sq/join (sq/table db :tableA)(sq/table db :tableB)(sq/where (= :tableA.id 27219))) (sq/where (= :tableA.group_id 27202))) (sq/union (sq/select (sq/join (sq/table db :tableA)(sq/table db :tableB)(sq/where (= :tableA.id 27391))) (sq/where (= :tableA.group_id 27353))) :all))

The sql that it generates: (SELECT tableA.,tableB. FROM tableA JOIN tableB ON (tableA.id = 27219) WHERE (tableA.groupid = 27202)) UNION ALL (SELECT tableA.,tableB._ FROM tableA JOIN tableB ON (tableA.id = 27391) WHERE (tableA.group_id = ?))

The sql that it should generate: (SELECT tableA.,tableB. FROM tableA JOIN tableB ON (tableA.id = 27219) WHERE (tableA.groupid = 27202)) UNION ALL (SELECT tableA.,tableB._ FROM tableA JOIN tableB ON (tableA.id = 27391) WHERE (tableA.group_id = 27353))

Here's a bit more information. If there's no join in the query, the generated sql is correct:

(-> (sq/select (sq/table db :tableA) (sq/where (= :tableA.id 27219))) (sq/union (sq/select (sq/table db :tableA) (sq/where (= :tableA.group_id 27353))) :all))

(SELECT tableA.* FROM tableA WHERE (tableA.id = 27219)) UNION ALL (SELECT tableA.* FROM tableA WHERE (tableA.group_id = 27353))

bendlas commented 13 years ago

Duplicate of #81

LauJensen commented 12 years ago

Fixed in HEAD