Django

Code

Ticket #7111 (closed: fixed)

Opened 2 months ago

Last modified 2 months ago

Double negation in sql query fails on Oracle

Reported by: ikelly Assigned to: ikelly
Milestone: Component: Database wrapper
Version: SVN Keywords: oracle
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

04/28/08 12:58:51 changed by ikelly

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

04/29/08 15:00:45 changed by ikelly

  • owner changed from nobody to ikelly.
  • status changed from new to assigned.

04/29/08 15:55:11 changed by ikelly

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #7111 (Double negation in sql query fails on Oracle)




Change Properties
Action