From 30ce7e93f4068b00ced0db785fdd578dc8a45975 Mon Sep 17 00:00:00 2001 From: Kai Groner Date: Mon, 26 Jan 2015 14:49:40 -0500 Subject: [PATCH] Partial index support with sqlite dialects. From https://www.sqlite.org/partialindex.html > Partial indexes have been supported in SQLite since version 3.8.0. Reflection does not expose the predicate of partial indexes. The postgresql dialect does detect such indexes and issue a warning. I looked into matching this level of support, but the sqlite pragma index_info does not expose the predicate. Getting this data would probably require parsing the CREATE INDEX statement from sqlite_master. --- lib/sqlalchemy/dialects/sqlite/base.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 1ed89bacb3..437a7794ac 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -714,9 +714,20 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): return preparer.format_table(table, use_schema=False) def visit_create_index(self, create): - return super(SQLiteDDLCompiler, self).visit_create_index( + index = create.element + + text = super(SQLiteDDLCompiler, self).visit_create_index( create, include_table_schema=False) + whereclause = index.dialect_options["sqlite"]["where"] + if whereclause is not None: + where_compiled = self.sql_compiler.process( + whereclause, include_table=False, + literal_binds=True) + text += " WHERE " + where_compiled + + return text + class SQLiteTypeCompiler(compiler.GenericTypeCompiler): def visit_large_binary(self, type_, **kw): @@ -823,7 +834,10 @@ class SQLiteDialect(default.DefaultDialect): construct_arguments = [ (sa_schema.Table, { "autoincrement": False - }) + }), + (sa_schema.Index, { + "where": None, + }), ] _broken_fk_pragma_quotes = False -- 2.47.3