Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dialect/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ use crate::dialect::Dialect;
pub struct AnsiDialect {}

impl Dialect for AnsiDialect {
/// The SQL standard uses double quotes for delimited identifiers.
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('"')
}

fn is_identifier_start(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase()
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ impl Dialect for BigQueryDialect {
ch == '`'
}

/// See <https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_identifiers>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('`')
}

fn supports_projection_trailing_commas(&self) -> bool {
true
}
Expand Down
7 changes: 7 additions & 0 deletions src/dialect/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ impl Dialect for ClickHouseDialect {
self.is_identifier_start(ch) || ch.is_ascii_digit()
}

/// ClickHouse accepts both backticks and double quotes, but its own
/// formatter emits backticks by default.
/// See <https://clickhouse.com/docs/en/sql-reference/syntax#identifiers>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('`')
}

fn supports_string_literal_backslash_escape(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ impl Dialect for DatabricksDialect {
matches!(ch, '`')
}

/// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('`')
}

fn is_identifier_start(&self, ch: char) -> bool {
matches!(ch, 'a'..='z' | 'A'..='Z' | '_')
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl Dialect for DuckDbDialect {
ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
}

/// See <https://duckdb.org/docs/stable/sql/dialect/keywords_and_identifiers>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('"')
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl Dialect for HiveDialect {
(ch == '"') || (ch == '`')
}

/// See <https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RulesforColumnNames>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('`')
}

fn is_identifier_start(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '$'
}
Expand Down
15 changes: 14 additions & 1 deletion src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,9 +2001,22 @@ mod tests {
#[test]
fn identifier_quote_style() {
let tests: Vec<(&dyn Dialect, &str, Option<char>)> = vec![
(&AnsiDialect {}, "id", Some('"')),
(&BigQueryDialect {}, "id", Some('`')),
(&ClickHouseDialect {}, "id", Some('`')),
(&DatabricksDialect {}, "id", Some('`')),
(&DuckDbDialect {}, "id", Some('"')),
(&GenericDialect {}, "id", None),
(&SQLiteDialect {}, "id", Some('`')),
(&HiveDialect {}, "id", Some('`')),
(&MsSqlDialect {}, "id", Some('[')),
(&MySqlDialect {}, "id", Some('`')),
(&OracleDialect {}, "id", Some('"')),
(&PostgreSqlDialect {}, "id", Some('"')),
(&RedshiftSqlDialect {}, "id", Some('"')),
(&SnowflakeDialect {}, "id", Some('"')),
(&SQLiteDialect {}, "id", Some('`')),
(&SparkSqlDialect {}, "id", Some('`')),
(&TeradataDialect {}, "id", Some('"')),
];

for (dialect, ident, expected) in tests {
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl Dialect for RedshiftSqlDialect {
PostgreSqlDialect {}.is_identifier_part(ch) || ch == '#'
}

/// See <https://docs.aws.amazon.com/redshift/latest/dg/r_names.html>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('"')
}

/// redshift has `CONVERT(type, value)` instead of `CONVERT(value, type)`
/// <https://docs.aws.amazon.com/redshift/latest/dg/r_CONVERT_function.html>
fn convert_type_before_value(&self) -> bool {
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ impl Dialect for SnowflakeDialect {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
}

/// See <https://docs.snowflake.com/en/sql-reference/identifiers-syntax>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('"')
}

fn supports_projection_trailing_commas(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/spark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ impl Dialect for SparkSqlDialect {
matches!(ch, '`')
}

/// See <https://spark.apache.org/docs/latest/sql-ref-identifier.html>
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('`')
}

fn is_identifier_start(&self, ch: char) -> bool {
matches!(ch, 'a'..='z' | 'A'..='Z' | '_')
}
Expand Down
Loading