Opened 17 years ago

Closed 17 years ago

#7111 closed (fixed)

Double negation in sql query fails on Oracle

Reported by: Erin Kelly Owned by: Erin Kelly
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: oracle
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [3]: qs = Item.objects.exclude(~Q(tags__name='t1', name='one'))

In [4]: qs.query.as_sql()
Out[4]:
('SELECT "TEST_ITEM"."ID", "TEST_ITEM"."NAME", "TEST_ITEM"."CREATED", "TEST_ITEM"."CREATOR_ID", "TEST_ITEM"."NOTE_ID" FROM "TEST_ITEM" INNER JOIN "TEST_NOTE" ON ("TEST_ITEM"."NOTE_ID" = "TEST_NOTE"."ID") WHERE NOT NOT ("TEST_ITEM"."NAME" = %s  AND "TEST_ITEM"."ID" IN (SELECT "TEST_ITEM_TAGS"."ITEM_ID" FROM "TEST_ITEM_TAGS" INNER JOIN "TEST_TAG" ON ("TEST_ITEM_TAGS"."TAG_ID" = "TEST_TAG"."ID") WHERE "TEST_TAG"."NAME" = %s )) ORDER BY "TEST_NOTE"."NOTE" DESC, "TEST_ITEM"."NAME" ASC',
 ('one', 't1'))

This causes an error in Oracle because the "NOT NOT (condition)" syntax in the where clause is invalid. The syntax "NOT (NOT (condition))" would work.

Change History (3)

comment:1 by Erin Kelly, 17 years ago

By the way, this query is lifted straight from the queries test.

comment:2 by Erin Kelly, 17 years ago

Owner: changed from nobody to Erin Kelly
Status: newassigned

comment:3 by Erin Kelly, 17 years ago

Resolution: fixed
Status: assignedclosed

(In [7509]) Fixed an Oracle error on double negations in where conditions. Fixed #7111

Note: See TracTickets for help on using tickets.
Back to Top