From: Mike Bayer Date: Wed, 27 Sep 2017 13:48:17 +0000 (-0400) Subject: Accomodate for multidimensional array in rewriting for COLLATE X-Git-Tag: rel_1_1_15~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f66a3dfc9ced6c57efa21dcb3111299ad24bb7a6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Accomodate for multidimensional array in rewriting for COLLATE 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) --- diff --git a/doc/build/changelog/unreleased_11/4006.rst b/doc/build/changelog/unreleased_11/4006.rst new file mode 100644 index 0000000000..d7ced2ba55 --- /dev/null +++ b/doc/build/changelog/unreleased_11/4006.rst @@ -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. diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 0ee65651de..01bb161287 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -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 ) diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index c236d34cf9..76b84afb5a 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -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(