From a8dcdb9b2806e1699ef48cba5884407abe46272f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 25 Jul 2014 16:08:21 -0400 Subject: [PATCH] - Fixed bug in :class:`.postgresql.array` object where comparison to a plain Python list would fail to use the correct array constructor. Pull request courtesy Andrew. fixes #3141 --- doc/build/changelog/changelog_09.rst | 10 ++++++++++ test/dialect/postgresql/test_compiler.py | 10 ++++++++++ test/dialect/postgresql/test_types.py | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 44b633a1d4..9d5614d683 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -13,6 +13,16 @@ .. changelog:: :version: 0.9.8 + .. change:: + :tags: bug, postgresql + :versions: 1.0.0 + :tickets: 3141 + :pullreq: github:124 + + Fixed bug in :class:`.postgresql.array` object where comparison + to a plain Python list would fail to use the correct array constructor. + Pull request courtesy Andrew. + .. change:: :tags: bug, postgresql :versions: 1.0.0 diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index c71852d90d..b08fb01603 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -501,6 +501,16 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): 'param_3': 3, 'param_2': 2} ) + def test_array_literal_compare(self): + self.assert_compile( + postgresql.array([1, 2]) == [3, 4, 5], + "ARRAY[%(param_1)s, %(param_2)s] = " + "ARRAY[%(param_3)s, %(param_4)s, %(param_5)s]", + checkparams={'param_5': 5, 'param_4': 4, 'param_1': 1, + 'param_3': 3, 'param_2': 2} + + ) + def test_array_literal_insert(self): m = MetaData() t = Table('t', m, Column('data', postgresql.ARRAY(Integer))) diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 33219ce4cb..457ddce0d8 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -644,6 +644,16 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): eq_(len(results), 1) eq_(results[0][0], [1, 2, 3, 4, 5, 6, ]) + def test_array_comparison(self): + arrtable = self.tables.arrtable + arrtable.insert().execute(intarr=[1, 2, 3], + strarr=[util.u('abc'), util.u('def')]) + results = select([arrtable.c.id]).\ + where(arrtable.c.intarr < [4, 5, 6]).execute()\ + .fetchall() + eq_(len(results), 1) + eq_(results[0][0], 3) + def test_array_subtype_resultprocessor(self): arrtable = self.tables.arrtable arrtable.insert().execute(intarr=[4, 5, 6], @@ -668,6 +678,15 @@ class ArrayTest(fixtures.TablesTest, AssertsExecutionResults): ), [1, 2, 3, 4, 5] ) + def test_array_literal_compare(self): + eq_( + testing.db.scalar( + select([ + postgresql.array([1, 2]) < [3, 4, 5] + ]) + ), True + ) + def test_array_getitem_single_type(self): arrtable = self.tables.arrtable is_(arrtable.c.intarr[1].type._type_affinity, Integer) -- 2.47.3