Skip to content
Merged
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
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/clickhouse_2686_dollar_identifier.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT a$b, c$$, d$e$, $$text$$, $tag$text$tag$ FROM t$1 WHERE x$y = 1
4 changes: 3 additions & 1 deletion src/dialect/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ impl Dialect for ClickHouseDialect {
}

fn is_identifier_part(&self, ch: char) -> bool {
self.is_identifier_start(ch) || ch.is_ascii_digit()
// Undocumented, but the server accepts `$` in identifiers for MySQL compatibility
// since https://github.com/ClickHouse/ClickHouse/pull/14232
self.is_identifier_start(ch) || ch.is_ascii_digit() || ch == '$'
}

/// ClickHouse accepts both backticks and double quotes, but its own
Expand Down
24 changes: 24 additions & 0 deletions tests/sqlparser_clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,30 @@ fn parse_update_on_cluster_and_settings() {
);
}

#[test]
fn parse_dollar_in_identifier() {
let select = clickhouse_and_generic().verified_only_select("SELECT a$b, c$$, d$e$ FROM t");
assert_eq!(
select.projection,
vec![
UnnamedExpr(Identifier(Ident::new("a$b"))),
UnnamedExpr(Identifier(Ident::new("c$$"))),
UnnamedExpr(Identifier(Ident::new("d$e$"))),
]
);
// Dollar-quoted strings still take precedence at the start of a token.
clickhouse_and_generic().verified_stmt("SELECT $$abc$$, $tag$abc$tag$");
// Tokenizes like ClickHouse does; only the parser rejects it.
let err = clickhouse()
.parse_sql_statements("INSERT I$$$$$$$$$$$$$$$$$$$$$$$$$$")
.unwrap_err();
assert!(matches!(err, ParserError(_)), "{err}");

all_dialects_where(|d| !d.is_identifier_part('$'))
.parse_sql_statements("SELECT a$b FROM t")
.unwrap_err();
}

fn clickhouse() -> TestedDialects {
TestedDialects::new(vec![Box::new(ClickHouseDialect {})])
}
Expand Down
Loading