From ec422fb70e0044ed42dcfda5fb1a7a65db322cf1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 8 Jun 2017 12:55:23 -0400 Subject: Render ARRAY index embedded between type and COLLATE Fixed bug where using :class:`.ARRAY` with a string type that features a collation would fail to produce the correct syntax within CREATE TABLE. The "COLLATE" must appear to the right of the array dimensions, so we are using regexp substitution to insert the brackets in the appropriate place. A more heavyweight solution would be that datatypes know how to split up their base type vs. modifiers, but as this is so specific to Postgresql ARRAY it's better to handle these cases more locally. Change-Id: I394c3c673eb60689e51b5301e51651972cfdb4c0 Fixes: #4006 --- lib/sqlalchemy/dialects/postgresql/base.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index e583bd5cf..b56ac5b10 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1873,9 +1873,15 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): return "BYTEA" def visit_ARRAY(self, type_, **kw): - return self.process(type_.item_type) + ('[]' * (type_.dimensions - if type_.dimensions - is not None else 1)) + + # TODO: pass **kw? + inner = self.process(type_.item_type) + return re.sub( + r'((?: COLLATE.*)?)$', + (r'[]\1' * + (type_.dimensions if type_.dimensions is not None else 1)), + inner + ) class PGIdentifierPreparer(compiler.IdentifierPreparer): -- cgit v1.2.1