korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Optionally parenthesize multiple JOIN expressions #356

Open hden opened 8 years ago

hden commented 8 years ago

[korma "0.4.2"]

Continued from #58

Google BigQuery fails when multiple JOIN expression are parenthesized. This can be easily reproduced by the following queries:

#  KORMA FORM
{:where [{:pred korma.sql.engine$do_group, :args [" AND " ({:pred korma.sql.engine$do_infix, :args [{:generated "[doh].[members].[c
ountry]"} "=" {:generated "'tw'"}]})]}],
 :group [{:generated "[doh.restaurants.country]"}],
 :table {:generated "[doh.bookings]"},
 :fields [[{:func "COUNT(%s)", :args ({:generated "*"})} :count]
            [:doh.restaurants.country "doh.restaurants.country"]],
 :joins
 [[:left "doh.members" {:pred korma.sql.engine$do_infix, :args [:doh.bookings.member_id "=" :doh.members.id]}]
  [:left "doh.restaurants" {:pred korma.sql.engine$do_infix, :args [:doh.bookings.restaurant_id "=" :doh.restaurants.id]}]],
 :order [[{:generated "[doh.restaurants.country]"} :ASC]]}
-- SQL
SELECT COUNT(*) AS [count], [doh.restaurants.country] AS [doh.restaurants.country]
FROM ([doh.bookings]
LEFT JOIN [doh.members] ON [doh.bookings.member_id] = [doh.members.id])
LEFT JOIN [doh.restaurants] ON [doh.bookings.restaurant_id] = [doh.restaurants.id]
WHERE ([doh.members.country] = 'tw')
GROUP BY [doh.restaurants.country]
ORDER BY [doh.restaurants.country] ASC

Error Message:

Query Failed
Error: Encountered "" at line 2, column 7.
venantius commented 6 years ago

This sounds like something we'd reasonably take a PR for.

I'm going through old issues and trying to clean them up. Is this still a priority?

If there hasn't been a response to this issue in 2 weeks, I'll close the ticket.