Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesting with union all extra parens #375

Closed
shay-rf opened this issue Dec 20, 2021 · 2 comments
Closed

Nesting with union all extra parens #375

shay-rf opened this issue Dec 20, 2021 · 2 comments
Assignees
Labels
bug It's broken, I'll fix it!

Comments

@shay-rf
Copy link

shay-rf commented Dec 20, 2021

Hi, I am building a query for BigQuery with union all and I am facing the following issue:

  • If I just pass the queries as input to union-all, those queries are not considered nested and there are no wrapping parens ( cause a syntax error on execution )
  • If I wrap each query with {:nest q}, then it wraps it twice. First due to the explicit nest and second because it is a nested query.

Not sure if I am missing something here.
As a simple way to reproduce this :
{:nest (h/select :*)}
Produces "((SELECT *))"

And in union all context:

(h/union-all
          {:nest (h/select :* )}
          {:nest (h/select :* )})
 => ((SELECT *)) UNION ALL ((SELECT *))

(h/union-all
          (h/select :* )
          (h/select :* ))
=> SELECT * UNION ALL SELECT *

Is there a way to achieve single wrapping? Can the union-all consider its params as nested queries?

@seancorfield
Copy link
Owner

Looks like my fix for #370 was a bit over-zealous. The syntax without nesting is correct for most databases (and if you do wrap the selects in parentheses, it is a syntax error for some databases) so it's unfortunate that BigQuery seems to require parentheses.

I'll get this fixed in the next few days and cut a new release.

@seancorfield seancorfield self-assigned this Dec 21, 2021
@seancorfield seancorfield added the bug It's broken, I'll fix it! label Dec 21, 2021
@shay-rf
Copy link
Author

shay-rf commented Dec 22, 2021

Thank you so much! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's broken, I'll fix it!
Projects
None yet
Development

No branches or pull requests

2 participants