Skip to content

Commit 7d72306

Browse files
committed
Use normal comma separation when displaying index columns
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
1 parent 3cfafea commit 7d72306

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/ast/dml.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ impl Display for CreateIndex {
106106
if let Some(value) = &self.using {
107107
write!(f, " USING {value} ")?;
108108
}
109-
write!(f, "({})", display_separated(&self.columns, ","))?;
109+
write!(f, "({})", display_comma_separated(&self.columns))?;
110110
if !self.include.is_empty() {
111-
write!(f, " INCLUDE ({})", display_separated(&self.include, ","))?;
111+
write!(f, " INCLUDE ({})", display_comma_separated(&self.include))?;
112112
}
113113
if let Some(value) = self.nulls_distinct {
114114
if value {

tests/sqlparser_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9175,7 +9175,7 @@ fn ensure_multiple_dialects_are_tested() {
91759175

91769176
#[test]
91779177
fn parse_create_index() {
9178-
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age DESC)";
9178+
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name, age DESC)";
91799179
let indexed_columns: Vec<IndexColumn> = vec![
91809180
IndexColumn {
91819181
operator_class: None,
@@ -9221,7 +9221,7 @@ fn parse_create_index() {
92219221

92229222
#[test]
92239223
fn test_create_index_with_using_function() {
9224-
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING BTREE (name,age DESC)";
9224+
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING BTREE (name, age DESC)";
92259225
let indexed_columns: Vec<IndexColumn> = vec![
92269226
IndexColumn {
92279227
operator_class: None,

tests/sqlparser_postgres.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ fn parse_array_multi_subscript() {
24862486

24872487
#[test]
24882488
fn parse_create_index() {
2489-
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2)";
2489+
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2)";
24902490
match pg().verified_stmt(sql) {
24912491
Statement::CreateIndex(CreateIndex {
24922492
name: Some(ObjectName(name)),
@@ -2517,7 +2517,7 @@ fn parse_create_index() {
25172517

25182518
#[test]
25192519
fn parse_create_anonymous_index() {
2520-
let sql = "CREATE INDEX ON my_table(col1,col2)";
2520+
let sql = "CREATE INDEX ON my_table(col1, col2)";
25212521
match pg().verified_stmt(sql) {
25222522
Statement::CreateIndex(CreateIndex {
25232523
name,
@@ -2577,7 +2577,7 @@ fn parse_create_indices_with_operator_classes() {
25772577
.unwrap_or_default()
25782578
);
25792579
let multi_column_sql_statement = format!(
2580-
"CREATE INDEX the_index_name ON users USING {expected_index_type} (column_name,concat_users_name(first_name, last_name){})",
2580+
"CREATE INDEX the_index_name ON users USING {expected_index_type} (column_name, concat_users_name(first_name, last_name){})",
25812581
expected_operator_class.as_ref().map(|oc| format!(" {oc}"))
25822582
.unwrap_or_default()
25832583
);
@@ -2698,7 +2698,7 @@ fn parse_create_indices_with_operator_classes() {
26982698
#[test]
26992699
fn parse_create_bloom() {
27002700
let sql =
2701-
"CREATE INDEX bloomidx ON tbloom USING BLOOM (i1,i2,i3) WITH (length = 80, col1 = 2, col2 = 2, col3 = 4)";
2701+
"CREATE INDEX bloomidx ON tbloom USING BLOOM (i1, i2, i3) WITH (length = 80, col1 = 2, col2 = 2, col3 = 4)";
27022702
match pg().verified_stmt(sql) {
27032703
Statement::CreateIndex(CreateIndex {
27042704
name: Some(ObjectName(name)),
@@ -2813,7 +2813,7 @@ fn parse_create_table_with_empty_inherits_fails() {
28132813

28142814
#[test]
28152815
fn parse_create_index_concurrently() {
2816-
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1,col2)";
2816+
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1, col2)";
28172817
match pg().verified_stmt(sql) {
28182818
Statement::CreateIndex(CreateIndex {
28192819
name: Some(ObjectName(name)),
@@ -2844,7 +2844,7 @@ fn parse_create_index_concurrently() {
28442844

28452845
#[test]
28462846
fn parse_create_index_with_predicate() {
2847-
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) WHERE col3 IS NULL";
2847+
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) WHERE col3 IS NULL";
28482848
match pg().verified_stmt(sql) {
28492849
Statement::CreateIndex(CreateIndex {
28502850
name: Some(ObjectName(name)),
@@ -2875,7 +2875,7 @@ fn parse_create_index_with_predicate() {
28752875

28762876
#[test]
28772877
fn parse_create_index_with_include() {
2878-
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) INCLUDE (col3)";
2878+
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) INCLUDE (col3)";
28792879
match pg().verified_stmt(sql) {
28802880
Statement::CreateIndex(CreateIndex {
28812881
name: Some(ObjectName(name)),
@@ -2906,7 +2906,7 @@ fn parse_create_index_with_include() {
29062906

29072907
#[test]
29082908
fn parse_create_index_with_nulls_distinct() {
2909-
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS NOT DISTINCT";
2909+
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) NULLS NOT DISTINCT";
29102910
match pg().verified_stmt(sql) {
29112911
Statement::CreateIndex(CreateIndex {
29122912
name: Some(ObjectName(name)),
@@ -2935,7 +2935,7 @@ fn parse_create_index_with_nulls_distinct() {
29352935
_ => unreachable!(),
29362936
}
29372937

2938-
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS DISTINCT";
2938+
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) NULLS DISTINCT";
29392939
match pg().verified_stmt(sql) {
29402940
Statement::CreateIndex(CreateIndex {
29412941
name: Some(ObjectName(name)),

0 commit comments

Comments
 (0)