]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Accomodate for multidimensional array in rewriting for COLLATE
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Sep 2017 13:48:17 +0000 (09:48 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Sep 2017 13:49:11 +0000 (09:49 -0400)
Made further fixes to the :class:`.ARRAY` class in conjunction with
COLLATE, as the fix made in :ticket:`4006` failed to accommodate
for a multidimentional array.

Change-Id: If3e438f8ce94ebae2196671c88a4914f3b743e60
Fixes: #4006
(cherry picked from commit 6652f72352730df12adb93d462f309a7efe1ff1f)

doc/build/changelog/unreleased_11/4006.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_types.py

diff --git a/doc/build/changelog/unreleased_11/4006.rst b/doc/build/changelog/unreleased_11/4006.rst
new file mode 100644 (file)
index 0000000..d7ced2b
--- /dev/null
@@ -0,0 +1,8 @@
+.. change:: 4006
+    :tags: bug, postgresql
+    :tickets: 4006
+    :versions: 1.2.0b3
+
+    Made further fixes to the :class:`.ARRAY` class in conjunction with
+    COLLATE, as the fix made in :ticket:`4006` failed to accommodate
+    for a multidimentional array.
index 0ee65651de60aca229e9eeb05655bf5285702e11..01bb161287b43dcbce6e2c24051b4937435f7d8c 100644 (file)
@@ -1869,8 +1869,10 @@ class PGTypeCompiler(compiler.GenericTypeCompiler):
         inner = self.process(type_.item_type)
         return re.sub(
             r'((?: COLLATE.*)?)$',
-            (r'[]\1' *
-             (type_.dimensions if type_.dimensions is not None else 1)),
+            (r'%s\1' % (
+                "[]" *
+                (type_.dimensions if type_.dimensions is not None else 1)
+            )),
             inner
         )
 
index c236d34cf9bf4c8adc370d3b558e736ab6d811ae..76b84afb5a5a236680b8ac1401efa92696154c2d 100644 (file)
@@ -822,6 +822,29 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase):
             'VARCHAR(30)[] COLLATE "en_US"'
         )
 
+    def test_array_type_render_str_multidim(self):
+        self.assert_compile(
+            postgresql.ARRAY(Unicode(30), dimensions=2),
+            "VARCHAR(30)[][]"
+        )
+
+        self.assert_compile(
+            postgresql.ARRAY(Unicode(30), dimensions=3),
+            "VARCHAR(30)[][][]"
+        )
+
+    def test_array_type_render_str_collate_multidim(self):
+        self.assert_compile(
+            postgresql.ARRAY(Unicode(30, collation="en_US"), dimensions=2),
+            'VARCHAR(30)[][] COLLATE "en_US"'
+        )
+
+        self.assert_compile(
+            postgresql.ARRAY(Unicode(30, collation="en_US"), dimensions=3),
+            'VARCHAR(30)[][][] COLLATE "en_US"'
+        )
+
+
     def test_array_int_index(self):
         col = column('x', postgresql.ARRAY(Integer))
         self.assert_compile(