diff options
author | Jakub Synowiec <github@jakubsynowiec.info> | 2018-12-01 13:26:43 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-12-01 13:30:42 -0500 |
commit | 46f9c3c7d4d2c31f3f1627dcf777bd3215e13e3d (patch) | |
tree | da59c24d59f055de5551880e9afd49ac0f033936 /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | c8dea359db9bea58dc64880d306dbee2a26df247 (diff) | |
download | sqlalchemy-46f9c3c7d4d2c31f3f1627dcf777bd3215e13e3d.tar.gz |
Fix PostgreSQL reflection of domains expressed as arrays
Fixed issue where reflection of a PostgreSQL domain that is expressed as an
array would fail to be recognized. Pull request courtesy Jakub Synowiec.
Fixes: #4377
Change-Id: I252c79ca435b87d4d9172b1c84e0e74e789ef676
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4380
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 8468d6099..ce809db9f 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -2600,6 +2600,12 @@ class PGDialect(default.DefaultDialect): def _get_column_info(self, name, format_type, default, notnull, domains, enums, schema, comment): + def _handle_array_type(attype): + return ( + attype.replace('[]', ''), # strip '[]' from integer[], etc. + attype.endswith('[]'), + ) + # strip (*) from character varying(5), timestamp(5) # with time zone, geometry(POLYGON), etc. attype = re.sub(r'\(.*\)', '', format_type) @@ -2607,11 +2613,11 @@ class PGDialect(default.DefaultDialect): # strip quotes from case sensitive enum names attype = re.sub(r'^"|"$', '', attype) - # strip '[]' from integer[], etc. - attype = attype.replace('[]', '') + # strip '[]' from integer[], etc. and check if an array + attype, is_array = _handle_array_type(attype) nullable = not notnull - is_array = format_type.endswith('[]') + charlen = re.search(r'\(([\d,]+)\)', format_type) if charlen: charlen = charlen.group(1) @@ -2676,6 +2682,7 @@ class PGDialect(default.DefaultDialect): elif attype in domains: domain = domains[attype] attype = domain['attype'] + attype, is_array = _handle_array_type(attype) # A table can't override whether the domain is nullable. nullable = domain['nullable'] if domain['default'] and not default: |