summaryrefslogtreecommitdiff
path: root/django/db/models/sql/where.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql/where.py')
-rw-r--r--django/db/models/sql/where.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 70ff5310f7..827046553d 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -135,10 +135,13 @@ class WhereNode(tree.Node):
conn = ' %s ' % self.connector
sql_string = conn.join(result)
if sql_string:
- if len(result) > 1:
- sql_string = '(%s)' % sql_string
if self.negated:
- sql_string = 'NOT %s' % sql_string
+ # Note that some backends (Oracle at least) need the
+ # parentheses even around single experssion in the
+ # negated case.
+ sql_string = 'NOT (%s)' % sql_string
+ elif len(result) > 1:
+ sql_string = '(%s)' % sql_string
return sql_string, result_params
def make_atom(self, child, qn, connection):