--- /dev/null
+.. change::
+ :tags: feature, mssql
+ :tickets: 4657
+
+ Added support for SQL Server filtered indexes, via the ``mssql_where``
+ parameter which works similarly to that of the ``postgresql_where`` index
+ function in the PostgreSQL dialect.
+
+ .. seealso::
+
+ :ref:`mssql_index_where`
\ No newline at end of file
would render the index as ``CREATE INDEX my_index ON table (x) INCLUDE (y)``
+.. _mssql_index_where:
+
+Filtered Indexes
+^^^^^^^^^^^^^^^^
+
+The ``mssql_where`` option renders WHERE(condition) for the given string
+names::
+
+ Index("my_index", table.c.x, mssql_where=table.c.x > 10)
+
+would render the index as ``CREATE INDEX my_index ON table (x) WHERE x > 10``.
+
+.. versionadded:: 1.3.4
+
Index ordering
^^^^^^^^^^^^^^
),
)
+ whereclause = index.dialect_options["mssql"]["where"]
+
+ if whereclause is not None:
+ where_compiled = self.sql_compiler.process(
+ whereclause, include_table=False, literal_binds=True
+ )
+ text += " WHERE " + where_compiled
+
# handle other included columns
if index.dialect_options["mssql"]["include"]:
inclusions = [
construct_arguments = [
(sa_schema.PrimaryKeyConstraint, {"clustered": None}),
(sa_schema.UniqueConstraint, {"clustered": None}),
- (sa_schema.Index, {"clustered": None, "include": None}),
+ (sa_schema.Index, {"clustered": None, "include": None, "where": None}),
(sa_schema.Column, {"identity_start": 1, "identity_increment": 1}),
]
schema.CreateIndex(idx), "CREATE CLUSTERED INDEX foo ON test (id)"
)
+ def test_index_where(self):
+ metadata = MetaData()
+ tbl = Table("test", metadata, Column("data", Integer))
+ idx = Index("test_idx_data_1", tbl.c.data, mssql_where=tbl.c.data > 1)
+ self.assert_compile(
+ schema.CreateIndex(idx),
+ "CREATE INDEX test_idx_data_1 ON test (data) WHERE data > 1"
+ )
+
def test_index_ordering(self):
metadata = MetaData()
tbl = Table(