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

Compound select statements ending in a VALUES-clause do not work properly. #2316

Closed
cubinator opened this issue Jul 1, 2020 · 6 comments
Closed
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Milestone

Comments

@cubinator
Copy link

Executing a compound select statement of the form

[select-core] [set-operator] [values-clause]
-- e.g. select * from table intersect values (...), ..., (...)
-    or values (...), ..., (...) intersect values (...), ..., (...)

results in a table that has the same shape as the actual result, but every cell is shaded red and contains loading... in italic. Currently, I can work around this by swapping the operands of the [set-operator] (unless it is except or both operands are values clauses), or by wrapping the values clause or the entire compound select statement in a with clause and selecting from it, i.e.

[values-clause] [set-operator] [select-core]

-- OR

with tmp as ( [values-clause] )
[select-core] [set-operator] select * from tmp

-- OR

with tmp as ( [select-core] [set-operator] [values-clause] )
select * from tmp

DB4S v3.11.2 [built for x86_64-little_endian-llp64] on Windows 10 (10.0) (winnt/10.0.18362) [x86_64]
using SQLite Version 3.27.2
and Qt 5.11.3

@chrisjlocke
Copy link
Member

One for @MKleusberg ...

MKleusberg added a commit that referenced this issue Jul 1, 2020
This disables the lazy population feature for queries in the Execute SQL
tab which contain a compound operator (UNION, EXCEPT, INTERSECT). Adding
a LIMIT clause to the statements (as needed for lazy population) results
in a syntax error, so running these queries does not show any data.

See issue #2316.
@MKleusberg
Copy link
Member

Thank you for reporting this issue! The problem is that we add a LIMIT x,y clause to the statement for lazy population. So SELECT * FROM tbl actually becomes SELECT * FROM tbl LIMIT 0,9999 or similar. For queries with compound/set operators this however results in a syntax error: SELECT * FROM tbl UNION VALUES(1,2,3) LIMIT 0,9999 is invalid.

Currently it's very hard for us to figure out when adding a LIMIT clause is permitted and when it's not. That's why I have disabled lazy population for all queries containing UNION, INTERSECT, or EXCEPT. It's not the perfect solution but for now it seems like the best compromise.

Can you try tomorrow's nightly build (https://nightlies.sqlitebrowser.org/latest/) and see if it's working for you?

@justinclift
Copy link
Member

justinclift commented Jul 1, 2020

Sounds like a candidate for 3.12.1 too. 😄

@cubinator
Copy link
Author

WOW! I didn't actually except a response this fast. The nightly build you linked produces the correct output for the problematic queries, and it seems to run just fine on all the databases I have lying around locally :)

@justinclift
Copy link
Member

Awesome. 😄

@MKleusberg Is this suitable for 3.12.1?

@MKleusberg
Copy link
Member

@justinclift Yeah, why not 😄

@MKleusberg MKleusberg added this to the 3.12.1 milestone Jul 10, 2020
@MKleusberg MKleusberg added bug Confirmed bugs or reports that are very likely to be bugs. and removed SQL Parser labels Jul 10, 2020
mgrojo pushed a commit that referenced this issue Aug 22, 2020
This disables the lazy population feature for queries in the Execute SQL
tab which contain a compound operator (UNION, EXCEPT, INTERSECT). Adding
a LIMIT clause to the statements (as needed for lazy population) results
in a syntax error, so running these queries does not show any data.

See issue #2316.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

5 participants