summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/databases/postgres.py3
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/select.py6
3 files changed, 8 insertions, 3 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index bab998d69..220c2a487 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -626,7 +626,8 @@ class PGCompiler(compiler.DefaultCompiler):
operators.update(
{
sql_operators.mod : '%%',
- sql_operators.ilike_op: 'ILIKE'
+ sql_operators.ilike_op: 'ILIKE',
+ sql_operators.notilike_op: 'NOT ILIKE'
}
)
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 545c0a1b4..8f2e3372a 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -80,7 +80,7 @@ OPERATORS = {
operators.like_op : 'LIKE',
operators.notlike_op : 'NOT LIKE',
operators.ilike_op : lambda x, y: "lower(%s) LIKE lower(%s)" % (x, y),
- operators.notilike_op : 'NOT ILIKE',
+ operators.notilike_op : lambda x, y: "lower(%s) NOT LIKE lower(%s)" % (x, y),
operators.between_op : 'BETWEEN',
operators.in_op : 'IN',
operators.notin_op : 'NOT IN',
diff --git a/test/sql/select.py b/test/sql/select.py
index b922c5c22..4c15bfb1b 100644
--- a/test/sql/select.py
+++ b/test/sql/select.py
@@ -527,9 +527,13 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A
def testilike(self):
stmt = table1.select(table1.c.name.ilike('%something%'))
- self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) LIKE :mytable_name_1")
+ self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) LIKE lower(:mytable_name_1)")
self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name ILIKE %(mytable_name_1)s", dialect=postgres.PGDialect())
+ stmt = table1.select(~table1.c.name.ilike('%something%'))
+ self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE lower(mytable.name) NOT LIKE lower(:mytable_name_1)")
+ self.assert_compile(stmt, "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name NOT ILIKE %(mytable_name_1)s", dialect=postgres.PGDialect())
+
def testforupdate(self):
self.assert_compile(table1.select(table1.c.myid==7, for_update=True), "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.myid = :mytable_myid_1 FOR UPDATE")