]> 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:48:17 +0000 (09:48 -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
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 d3aa1a756708b588fab42611bcaae84fd92ff247..f911ac1675771325d2aca0c6c295cb868fe81321 100644 (file)
@@ -1897,8 +1897,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 e08a9729e256739dc3117144bb150731474cae2e..499217fddd8d8cc9c0769c4ad4f307fad3a6423c 100644 (file)
@@ -842,6 +842,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(