Skip to content

Commit 85b6772

Browse files
committed
Add repeat to CREATE INDEX filter_predicate syntax
The [current syntax](https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver15#syntax-for-sql-server-and-azure-sql-database) for CREATE INDEX's `filter_predicate` appears to imply that only one or two conditions (joined with `AND`) are supported: ``` [snip] [ WHERE <filter_predicate> ] [snip] <filter_predicate> ::= <conjunct> [ AND <conjunct> ] <conjunct> ::= <disjunct> | <comparison> [snip] ``` In other words, one `conjunct` is required and a second may optionally be provided. However, in testing with SQL Server 2019 (spun up using Docker), an arbitrary number of `conjunct`s are allowed, with a query such as this succeeding and creating the index: ```sql CREATE UNIQUE INDEX [constraint] ON [test_table] ([_type]) WHERE ([status] = 'in_progress' AND [status] IN ('needs_changes', 'published') AND [status] = 'foo' AND [status] = 'bar' AND [status] = 'baz' AND [status] IN ('more', 'disjuncts')); ``` Given the above syntax works, a `[...n]` convention needs to be added to indicate multiple conditions are acceptable (https://docs.microsoft.com/en-us/sql/t-sql/language-elements/transact-sql-syntax-conventions-transact-sql?view=sql-server-ver15). This PR follows https://docs.microsoft.com/en-us/sql/t-sql/queries/search-condition-transact-sql?view=sql-server-ver15 and https://docs.microsoft.com/en-us/sql/powershell/query-expressions-and-uniform-resource-names?view=sql-server-ver15#syntax - examples in this repo's BNF syntax of multiple, optional conditions.
1 parent e3ab17f commit 85b6772

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/t-sql/statements/create-index-transact-sql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
138138
}
139139
140140
<filter_predicate> ::=
141-
<conjunct> [ AND <conjunct> ]
141+
<conjunct> [ AND ] [ ...n ]
142142
143143
<conjunct> ::=
144144
<disjunct> | <comparison>

0 commit comments

Comments
 (0)