]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in :class:`.postgresql.array` object where comparison
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jul 2014 20:08:21 +0000 (16:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Jul 2014 20:08:21 +0000 (16:08 -0400)
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
test/dialect/postgresql/test_compiler.py
test/dialect/postgresql/test_types.py

index 44b633a1d4c38664a5c728119bc236f298339817..9d5614d6834130fd078bd3709429457d7ca294d2 100644 (file)
 .. 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
index c71852d90d8417c85dc8bf65fdf469cae3b06892..b08fb016038b51383ceabd44fcd8e4fec5ef32c2 100644 (file)
@@ -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)))
index 33219ce4cba187315d9fcc773011fe64123a834d..457ddce0d891629e420365323c87c4414e39b765 100644 (file)
@@ -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)