summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-09-12 16:26:28 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-09-12 16:26:28 +0000
commitf53e5fc7cb408f067d18e7f3eabf993bd1887063 (patch)
tree99783bd2ca0e15de08ac3eaf3529f0fdf233783e /lib/sqlalchemy/dialects/postgresql/base.py
parent34870a0f6e7052c784eba8ad639cb4d981a2cd41 (diff)
parent69502725db4829a84872697fd6569631d2a3c47f (diff)
downloadsqlalchemy-f53e5fc7cb408f067d18e7f3eabf993bd1887063.tar.gz
Merge "Reflect mssql/postgresql filtered/partial indexes"
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index e40a730c5..819f1238a 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -2255,6 +2255,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
)
@@ -3638,9 +3642,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
@@ -3683,7 +3688,6 @@ class PGDialect(default.DefaultDialect):
idx_name,
unique,
expr,
- prd,
col,
col_num,
conrelid,
@@ -3691,6 +3695,7 @@ class PGDialect(default.DefaultDialect):
idx_option,
options,
amname,
+ filter_definition,
indnkeyatts,
) = row
@@ -3703,13 +3708,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:
@@ -3765,6 +3763,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 = {
@@ -3787,6 +3788,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