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

[sqlite] regression: invalid parentheses with UNION/INTERSECT #514

Closed
evgeniy-terekhin opened this issue Nov 8, 2022 · 3 comments · Fixed by #515
Closed

[sqlite] regression: invalid parentheses with UNION/INTERSECT #514

evgeniy-terekhin opened this issue Nov 8, 2022 · 3 comments · Fixed by #515

Comments

@evgeniy-terekhin
Copy link
Contributor

this PR introduced regression for sqlite
it renders parentheses around UNION/INTERSECT right arg. however it is illegal syntax in sqlite

sqlite> select 1 union all (select 1);
Parse error: near "(": syntax error
  select 1 union all (select 1);
                     ^--- error here
@evgeniy-terekhin
Copy link
Contributor Author

just to support my claim here is an issue from some other repo
kayak/pypika#537

@billy1624
Copy link
Member

Hey @evgeniy-terekhin, thanks for the bug report!

I think we can remove the parentheses around select statement after UNION operators. Some testing on Postgres, MySQL, MariaDB and SQLite.

The source code:

if !select.unions.is_empty() {
select.unions.iter().for_each(|(union_type, query)| {
match union_type {
UnionType::Intersect => write!(sql, " INTERSECT (").unwrap(),
UnionType::Distinct => write!(sql, " UNION (").unwrap(),
UnionType::Except => write!(sql, " EXCEPT (").unwrap(),
UnionType::All => write!(sql, " UNION ALL (").unwrap(),
}
self.prepare_select_statement(query, sql);
write!(sql, ")").unwrap();
});
}

@evgeniy-terekhin
Copy link
Contributor Author

evgeniy-terekhin commented Nov 9, 2022

@billy1624 please consider the linked fix

@billy1624 billy1624 linked a pull request Nov 9, 2022 that will close this issue
@billy1624 billy1624 moved this from Triage to Done in SeaQL Dev Tracker Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants