From: Kai Groner Date: Mon, 26 Jan 2015 19:49:40 +0000 (-0500) Subject: Partial index support with sqlite dialects. X-Git-Tag: rel_1_0_0b1~29^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=30ce7e93f4068b00ced0db785fdd578dc8a45975;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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. --- 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