mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-20 06:00:15 +00:00
[mssql] Support delimited identifiers in [square brackets]
T-SQL supports non-standard `[...]` quoting in addition to the widely supported and standard `"..."`: https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-2017
This commit is contained in:
parent
e6f5ff2926
commit
d0a782d8cc
2 changed files with 12 additions and 1 deletions
|
@ -4,6 +4,10 @@ use crate::dialect::Dialect;
|
||||||
pub struct MsSqlDialect {}
|
pub struct MsSqlDialect {}
|
||||||
|
|
||||||
impl Dialect for MsSqlDialect {
|
impl Dialect for MsSqlDialect {
|
||||||
|
fn is_delimited_identifier_start(&self, ch: char) -> bool {
|
||||||
|
ch == '"' || ch == '['
|
||||||
|
}
|
||||||
|
|
||||||
fn is_identifier_start(&self, ch: char) -> bool {
|
fn is_identifier_start(&self, ch: char) -> bool {
|
||||||
// See https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-2017#rules-for-regular-identifiers
|
// See https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-2017#rules-for-regular-identifiers
|
||||||
// We don't support non-latin "letters" currently.
|
// We don't support non-latin "letters" currently.
|
||||||
|
|
|
@ -27,7 +27,14 @@ fn parse_mssql_identifiers() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[test]
|
||||||
|
fn parse_mssql_delimited_identifiers() {
|
||||||
|
let _ = ms().one_statement_parses_to(
|
||||||
|
"SELECT [a.b!] [FROM] FROM foo [WHERE]",
|
||||||
|
"SELECT [a.b!] AS [FROM] FROM foo AS [WHERE]",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn ms() -> TestedDialects {
|
fn ms() -> TestedDialects {
|
||||||
TestedDialects {
|
TestedDialects {
|
||||||
dialects: vec![Box::new(MsSqlDialect {})],
|
dialects: vec![Box::new(MsSqlDialect {})],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue