mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-24 16:04:04 +00:00
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:
parent
3583514602
commit
00662c03fb
3 changed files with 14 additions and 14 deletions
|
@ -106,9 +106,9 @@ impl Display for CreateIndex {
|
||||||
if let Some(value) = &self.using {
|
if let Some(value) = &self.using {
|
||||||
write!(f, " USING {value} ")?;
|
write!(f, " USING {value} ")?;
|
||||||
}
|
}
|
||||||
write!(f, "({})", display_separated(&self.columns, ","))?;
|
write!(f, "({})", display_comma_separated(&self.columns))?;
|
||||||
if !self.include.is_empty() {
|
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 let Some(value) = self.nulls_distinct {
|
||||||
if value {
|
if value {
|
||||||
|
|
|
@ -9175,7 +9175,7 @@ fn ensure_multiple_dialects_are_tested() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index() {
|
fn parse_create_index() {
|
||||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age DESC)";
|
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name, age DESC)";
|
||||||
let indexed_columns: Vec<IndexColumn> = vec![
|
let indexed_columns: Vec<IndexColumn> = vec![
|
||||||
IndexColumn {
|
IndexColumn {
|
||||||
operator_class: None,
|
operator_class: None,
|
||||||
|
@ -9221,7 +9221,7 @@ fn parse_create_index() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_index_with_using_function() {
|
fn test_create_index_with_using_function() {
|
||||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING BTREE (name,age DESC)";
|
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING BTREE (name, age DESC)";
|
||||||
let indexed_columns: Vec<IndexColumn> = vec![
|
let indexed_columns: Vec<IndexColumn> = vec![
|
||||||
IndexColumn {
|
IndexColumn {
|
||||||
operator_class: None,
|
operator_class: None,
|
||||||
|
|
|
@ -2486,7 +2486,7 @@ fn parse_array_multi_subscript() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index() {
|
fn parse_create_index() {
|
||||||
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2)";
|
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2)";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2517,7 +2517,7 @@ fn parse_create_index() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_anonymous_index() {
|
fn parse_create_anonymous_index() {
|
||||||
let sql = "CREATE INDEX ON my_table(col1,col2)";
|
let sql = "CREATE INDEX ON my_table(col1, col2)";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name,
|
name,
|
||||||
|
@ -2577,7 +2577,7 @@ fn parse_create_indices_with_operator_classes() {
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
);
|
);
|
||||||
let multi_column_sql_statement = format!(
|
let multi_column_sql_statement = format!(
|
||||||
"CREATE INDEX the_index_name ON users USING {expected_index_type} (column_name,concat_users_name(first_name, last_name){})",
|
"CREATE INDEX the_index_name ON users USING {expected_index_type} (column_name, concat_users_name(first_name, last_name){})",
|
||||||
expected_operator_class.as_ref().map(|oc| format!(" {oc}"))
|
expected_operator_class.as_ref().map(|oc| format!(" {oc}"))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
);
|
);
|
||||||
|
@ -2698,7 +2698,7 @@ fn parse_create_indices_with_operator_classes() {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_bloom() {
|
fn parse_create_bloom() {
|
||||||
let sql =
|
let sql =
|
||||||
"CREATE INDEX bloomidx ON tbloom USING BLOOM (i1,i2,i3) WITH (length = 80, col1 = 2, col2 = 2, col3 = 4)";
|
"CREATE INDEX bloomidx ON tbloom USING BLOOM (i1, i2, i3) WITH (length = 80, col1 = 2, col2 = 2, col3 = 4)";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2813,7 +2813,7 @@ fn parse_create_table_with_empty_inherits_fails() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index_concurrently() {
|
fn parse_create_index_concurrently() {
|
||||||
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1,col2)";
|
let sql = "CREATE INDEX CONCURRENTLY IF NOT EXISTS my_index ON my_table(col1, col2)";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2844,7 +2844,7 @@ fn parse_create_index_concurrently() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index_with_predicate() {
|
fn parse_create_index_with_predicate() {
|
||||||
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) WHERE col3 IS NULL";
|
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) WHERE col3 IS NULL";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2875,7 +2875,7 @@ fn parse_create_index_with_predicate() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index_with_include() {
|
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) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2897,7 +2897,7 @@ fn parse_create_index_with_include() {
|
||||||
assert!(!concurrently);
|
assert!(!concurrently);
|
||||||
assert!(if_not_exists);
|
assert!(if_not_exists);
|
||||||
assert_eq_vec(&["col1", "col2"], &columns);
|
assert_eq_vec(&["col1", "col2"], &columns);
|
||||||
assert_eq_vec(&["col3"], &include);
|
assert_eq_vec(&["col3", "col4"], &include);
|
||||||
assert!(with.is_empty());
|
assert!(with.is_empty());
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -2906,7 +2906,7 @@ fn parse_create_index_with_include() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_index_with_nulls_distinct() {
|
fn parse_create_index_with_nulls_distinct() {
|
||||||
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS NOT DISTINCT";
|
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) NULLS NOT DISTINCT";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
@ -2935,7 +2935,7 @@ fn parse_create_index_with_nulls_distinct() {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1,col2) NULLS DISTINCT";
|
let sql = "CREATE INDEX IF NOT EXISTS my_index ON my_table(col1, col2) NULLS DISTINCT";
|
||||||
match pg().verified_stmt(sql) {
|
match pg().verified_stmt(sql) {
|
||||||
Statement::CreateIndex(CreateIndex {
|
Statement::CreateIndex(CreateIndex {
|
||||||
name: Some(ObjectName(name)),
|
name: Some(ObjectName(name)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue