-
Notifications
You must be signed in to change notification settings - Fork 304
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
SELECT statements are enclosed in a parenthesis when using UNION / INTERSECTION operators #537
Comments
I am experiencing same issue while executing >>>pypika.__version__
'0.48.0'
>>>from pypika import Query
>>>from pypika import Table
>>>t1 = Table('t1')
>>>q1 = Query.from_(t1).select('*').orderby(t1.r1)
>>>q2 = Query.from_(t1).select('*').where(t1.r1.lte(10))
>>>q_ex = q1.except_of(q2)
>>>q_ex.get_sql()
'(SELECT * FROM "t1" ORDER BY "r1") EXCEPT (SELECT * FROM "t1" WHERE "r1"<=10)' TarantoolDB (SQL-101 syntax) throws also syntax error due to parenthesis enclosure of the statements Correct syntax in my case is same as @mukund109 proposed. SELECT * FROM "t1" ORDER BY "r1" EXCEPT SELECT * FROM "t1" WHERE "r1"<=10 |
pypika/pypika/tests/test_joins.py Lines 708 to 712 in 7d0bc58
pypika/pypika/tests/test_joins.py Lines 1114 to 1117 in 7d0bc58
test shell: docker pull nouchka/sqlite3
docker run -it --rm nouchka/sqlite3 test sql: CREATE TABLE a ( id int );
INSERT INTO a (id) VALUES ( 1 );
INSERT INTO a (id) VALUES ( 2 );
CREATE TABLE b ( id int );
INSERT INTO b (id) VALUES ( 3 );
INSERT INTO b (id) VALUES ( 4 );
SELECT * FROM "a" UNION SELECT * FROM "b";
(SELECT * FROM "a") UNION (SELECT * FROM "b"); test log: sqlite> SELECT * FROM "a" UNION SELECT * FROM "b";
1
2
3
4
sqlite> (SELECT * FROM "a") UNION (SELECT * FROM "b");
Error: near "(": syntax error I feel this problem requires a lot of code modification. |
Pypika encloses the
SELECT
statements in a parenthesis when using a UNION or INTERSECTION operator (haven't tried other set operations)SQLite throws a syntax error for this. It doesn't allow the
SELECT
statements to be enclosed in parenthesis - see SQLite docsAccording to SQLite this is the correct way of doing it
The text was updated successfully, but these errors were encountered: