diff options
author | RamonWill <ramonwilliams@hotmail.co.uk> | 2020-08-20 15:05:39 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-12 10:30:43 -0400 |
commit | 69502725db4829a84872697fd6569631d2a3c47f (patch) | |
tree | a4035a47bb0def00afa405c8fdfe8215ae3d468e /lib/sqlalchemy/dialects/postgresql/base.py | |
parent | 544ef23cd36b0ea30a13c5158121ba5ea7573f03 (diff) | |
download | sqlalchemy-69502725db4829a84872697fd6569631d2a3c47f.tar.gz |
Reflect mssql/postgresql filtered/partial indexes
Added support for inspection / reflection of partial indexes / filtered
indexes, i.e. those which use the ``mssql_where`` or ``postgresql_where``
parameters, with :class:`_schema.Index`. The entry is both part of the
dictionary returned by :meth:`.Inspector.get_indexes` as well as part of a
reflected :class:`_schema.Index` construct that was reflected. Pull
request courtesy Ramon Williams.
**Have a nice day!**
Fixes: #4966
Closes: #5504
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5504
Pull-request-sha: b3018bac987081193b2e65cfdb6aeb7d5d270fcd
Change-Id: Icbb2f93d1545700718ccb5222097185b815f5dbc
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index c56cccd8d..409511416 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -2131,6 +2131,10 @@ class PGDDLCompiler(compiler.DDLCompiler): whereclause = index.dialect_options["postgresql"]["where"] if whereclause is not None: + whereclause = coercions.expect( + roles.DDLExpressionRole, whereclause + ) + where_compiled = self.sql_compiler.process( whereclause, include_table=False, literal_binds=True ) @@ -3459,9 +3463,10 @@ class PGDialect(default.DefaultDialect): IDX_SQL = """ SELECT i.relname as relname, - ix.indisunique, ix.indexprs, ix.indpred, + ix.indisunique, ix.indexprs, a.attname, a.attnum, c.conrelid, ix.indkey::varchar, ix.indoption::varchar, i.reloptions, am.amname, + pg_get_expr(ix.indpred, ix.indrelid), %s as indnkeyatts FROM pg_class t @@ -3504,7 +3509,6 @@ class PGDialect(default.DefaultDialect): idx_name, unique, expr, - prd, col, col_num, conrelid, @@ -3512,6 +3516,7 @@ class PGDialect(default.DefaultDialect): idx_option, options, amname, + filter_definition, indnkeyatts, ) = row @@ -3524,13 +3529,6 @@ class PGDialect(default.DefaultDialect): sv_idx_name = idx_name continue - if prd and not idx_name == sv_idx_name: - util.warn( - "Predicate of partial index %s ignored during reflection" - % idx_name - ) - sv_idx_name = idx_name - has_idx = idx_name in indexes index = indexes[idx_name] if col is not None: @@ -3586,6 +3584,9 @@ class PGDialect(default.DefaultDialect): if amname and amname != "btree": index["amname"] = amname + if filter_definition: + index["postgresql_where"] = filter_definition + result = [] for name, idx in indexes.items(): entry = { @@ -3608,6 +3609,10 @@ class PGDialect(default.DefaultDialect): entry.setdefault("dialect_options", {})[ "postgresql_using" ] = idx["amname"] + if "postgresql_where" in idx: + entry.setdefault("dialect_options", {})[ + "postgresql_where" + ] = idx["postgresql_where"] result.append(entry) return result |