summaryrefslogtreecommitdiff
path: root/test/dialect/test_postgresql.py
diff options
context:
space:
mode:
authorAudrius Kažukauskas <audrius@neutrino.lt>2012-11-20 23:24:34 +0200
committerAudrius Kažukauskas <audrius@neutrino.lt>2012-11-20 23:24:34 +0200
commit8134f2d0bfadc461b015104ff842f57962d89b0a (patch)
tree032d70eaa6923589b52cce7595ade1b7f222c7da /test/dialect/test_postgresql.py
parentfe8f8349c9f46abe37cd9de7876df0eeb5e12c94 (diff)
downloadsqlalchemy-8134f2d0bfadc461b015104ff842f57962d89b0a.tar.gz
Add special containment operation methods for PG array type
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r--test/dialect/test_postgresql.py81
1 files changed, 69 insertions, 12 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index fe45c441c..46dab3df9 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -290,25 +290,41 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
"CAST(x AS INTEGER[])"
)
self.assert_compile(
- c[5],
- "x[%(x_1)s]",
- checkparams={'x_1': 5}
+ c[5],
+ "x[%(x_1)s]",
+ checkparams={'x_1': 5}
)
self.assert_compile(
- c[5:7],
- "x[%(x_1)s:%(x_2)s]",
- checkparams={'x_2': 7, 'x_1': 5}
+ c[5:7],
+ "x[%(x_1)s:%(x_2)s]",
+ checkparams={'x_2': 7, 'x_1': 5}
)
self.assert_compile(
- c[5:7][2:3],
- "x[%(x_1)s:%(x_2)s][%(param_1)s:%(param_2)s]",
- checkparams={'x_2': 7, 'x_1': 5, 'param_1':2, 'param_2':3}
+ c[5:7][2:3],
+ "x[%(x_1)s:%(x_2)s][%(param_1)s:%(param_2)s]",
+ checkparams={'x_2': 7, 'x_1': 5, 'param_1':2, 'param_2':3}
)
self.assert_compile(
- c[5:7][3],
- "x[%(x_1)s:%(x_2)s][%(param_1)s]",
- checkparams={'x_2': 7, 'x_1': 5, 'param_1':3}
+ c[5:7][3],
+ "x[%(x_1)s:%(x_2)s][%(param_1)s]",
+ checkparams={'x_2': 7, 'x_1': 5, 'param_1':3}
+ )
+
+ self.assert_compile(
+ c.contains([1]),
+ 'x @> %(x_1)s',
+ checkparams={'x_1': [1]}
+ )
+ self.assert_compile(
+ c.contained_by([2]),
+ 'x <@ %(x_1)s',
+ checkparams={'x_1': [2]}
+ )
+ self.assert_compile(
+ c.overlap([3]),
+ 'x && %(x_1)s',
+ checkparams={'x_1': [3]}
)
def test_array_literal_type(self):
@@ -2244,6 +2260,47 @@ class ArrayTest(fixtures.TestBase, AssertsExecutionResults):
[7, 8]
)
+ def test_array_contains_exec(self):
+ with testing.db.connect() as conn:
+ conn.execute(
+ arrtable.insert(),
+ intarr=[4, 5, 6]
+ )
+ eq_(
+ conn.scalar(
+ select([arrtable.c.intarr]).
+ where(arrtable.c.intarr.contains([4, 5]))
+ ),
+ [4, 5, 6]
+ )
+
+ def test_array_contained_by_exec(self):
+ with testing.db.connect() as conn:
+ conn.execute(
+ arrtable.insert(),
+ intarr=[6, 5, 4]
+ )
+ eq_(
+ conn.scalar(
+ select([arrtable.c.intarr.contained_by([4, 5, 6, 7])])
+ ),
+ True
+ )
+
+ def test_array_overlap_exec(self):
+ with testing.db.connect() as conn:
+ conn.execute(
+ arrtable.insert(),
+ intarr=[4, 5, 6]
+ )
+ eq_(
+ conn.scalar(
+ select([arrtable.c.intarr]).
+ where(arrtable.c.intarr.overlap([7, 6]))
+ ),
+ [4, 5, 6]
+ )
+
@testing.provide_metadata
def test_tuple_flag(self):
metadata = self.metadata