Display CREATE INDEX column list separated by commas with spaces

The column list in `CREATE INDEX` now matches the style used elsewhere,
e.g. in `TableConstraint`, which is to use spaces after commas.

```sql
-- before:
CREATE INDEX idx_name ON table_name (column1,column2,column3);
-- after:
CREATE INDEX idx_name ON table_name (column1, column2, column3);
```

When `CreateIndex` was added, there was no explanation for the lack of
spaces, so I assume it was just author preference. But standard style in
all documentation I've seen is to use spaces after commas (including
[MSSQL]'s documentation of `INCLUDE`, which copied the no-spaces style
when added).

[MSSQL]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver17#i-create-an-index-with-included-non-key-columns
This commit is contained in:
Michael Victor Zink 2025-07-07 11:03:35 -07:00
parent 3583514602
commit 00662c03fb
3 changed files with 14 additions and 14 deletions

View file

@ -106,9 +106,9 @@ impl Display for CreateIndex {
if let Some(value) = &self.using {
write!(f, " USING {value} ")?;
}
write!(f, "({})", display_separated(&self.columns, ","))?;
write!(f, "({})", display_comma_separated(&self.columns))?;
if !self.include.is_empty() {
write!(f, " INCLUDE ({})", display_separated(&self.include, ","))?;
write!(f, " INCLUDE ({})", display_comma_separated(&self.include))?;
}
if let Some(value) = self.nulls_distinct {
if value {

View file

@ -2875,7 +2875,7 @@ fn parse_create_index_with_predicate() {
#[test]
fn parse_create_index_with_include() {
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) INCLUDE (col3)";
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) INCLUDE (col3, col4)";
match pg().verified_stmt(sql) {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
@ -2897,7 +2897,7 @@ fn parse_create_index_with_include() {
assert!(!concurrently);
assert!(if_not_exists);
assert_eq_vec(&["col1", "col2"], &columns);
assert_eq_vec(&["col3"], &include);
assert_eq_vec(&["col3", "col4"], &include);
assert!(with.is_empty());
}
_ => unreachable!(),