diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-26 09:45:06 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-26 09:50:46 -0400 |
commit | 4b5d162ed028558ac38c687d69f26ce93741789d (patch) | |
tree | d07ff1d069b0d28d9b98fca24e412eb1f32cd102 /test/dialect/postgresql/test_compiler.py | |
parent | e429ef1d31343b99e885f58a79800ae490155294 (diff) | |
download | sqlalchemy-4b5d162ed028558ac38c687d69f26ce93741789d.tar.gz |
Remove erroneous assertion from array._bind_param
Fixed bug where Postgresql operators such as
:meth:`.postgresql.ARRAY.Comparator.contains` and
:meth:`.postgresql.ARRAY.Comparator.contained_by` would fail to function
correctly for non-integer values when used against a
:class:`.postgresql.array` object, due to an erroneous assert statement.
Fixes: #4822
Change-Id: I886aca4c86dc7d64e9d0dfc1d910a0ae64d775a1
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r-- | test/dialect/postgresql/test_compiler.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index b65361bda..83e3ee3fd 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1244,6 +1244,83 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): }, ) + def test_array_literal_contains(self): + self.assert_compile( + postgresql.array([1, 2]).contains([3, 4, 5]), + "ARRAY[%(param_1)s, %(param_2)s] @> ARRAY[%(param_3)s, " + "%(param_4)s, %(param_5)s]", + checkparams={ + "param_1": 1, + "param_2": 2, + "param_3": 3, + "param_4": 4, + "param_5": 5, + }, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contains([""]), + "ARRAY[%(param_1)s, %(param_2)s] @> ARRAY[%(param_3)s]", + checkparams={"param_1": "a", "param_2": "b", "param_3": ""}, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contains([]), + "ARRAY[%(param_1)s, %(param_2)s] @> ARRAY[]", + checkparams={"param_1": "a", "param_2": "b"}, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contains([0]), + "ARRAY[%(param_1)s, %(param_2)s] @> ARRAY[%(param_3)s]", + checkparams={"param_1": "a", "param_2": "b", "param_3": 0}, + ) + + def test_array_literal_contained_by(self): + self.assert_compile( + postgresql.array(["a", "b"]).contained_by(["a", "b", "c"]), + "ARRAY[%(param_1)s, %(param_2)s] <@ ARRAY[%(param_3)s, " + "%(param_4)s, %(param_5)s]", + checkparams={ + "param_1": "a", + "param_2": "b", + "param_3": "a", + "param_4": "b", + "param_5": "c", + }, + ) + + self.assert_compile( + postgresql.array([1, 2]).contained_by([3, 4, 5]), + "ARRAY[%(param_1)s, %(param_2)s] <@ ARRAY[%(param_3)s, " + "%(param_4)s, %(param_5)s]", + checkparams={ + "param_1": 1, + "param_2": 2, + "param_3": 3, + "param_4": 4, + "param_5": 5, + }, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contained_by([""]), + "ARRAY[%(param_1)s, %(param_2)s] <@ ARRAY[%(param_3)s]", + checkparams={"param_1": "a", "param_2": "b", "param_3": ""}, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contained_by([]), + "ARRAY[%(param_1)s, %(param_2)s] <@ ARRAY[]", + checkparams={"param_1": "a", "param_2": "b"}, + ) + + self.assert_compile( + postgresql.array(["a", "b"]).contained_by([0]), + "ARRAY[%(param_1)s, %(param_2)s] <@ ARRAY[%(param_3)s]", + checkparams={"param_1": "a", "param_2": "b", "param_3": 0}, + ) + def test_array_literal_insert(self): m = MetaData() t = Table("t", m, Column("data", postgresql.ARRAY(Integer))) |