mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-13 15:32:03 +00:00
Store original, quoted form in SQLIdent
Also move more things to use SQLIdent instead of String in the hope of making it a newtype eventually. Add tests that quoted identifiers round-trip parsing/serialization correctly.
This commit is contained in:
parent
07790fe4c4
commit
e0ceacd1ad
5 changed files with 54 additions and 23 deletions
|
@ -427,6 +427,34 @@ fn parse_select_version() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_delimited_identifiers() {
|
||||
// check that quoted identifiers in any position remain quoted after serialization
|
||||
let sql = r#"SELECT "alias"."bar baz", "myfun"(), "simple id" FROM "a table" AS "alias""#;
|
||||
let select = verified_only_select(sql);
|
||||
// check SELECT
|
||||
assert_eq!(3, select.projection.len());
|
||||
assert_eq!(
|
||||
&ASTNode::SQLCompoundIdentifier(vec![r#""alias""#.to_string(), r#""bar baz""#.to_string()]),
|
||||
expr_from_projection(&select.projection[0]),
|
||||
);
|
||||
assert_eq!(
|
||||
&ASTNode::SQLFunction {
|
||||
id: r#""myfun""#.to_string(),
|
||||
args: vec![]
|
||||
},
|
||||
expr_from_projection(&select.projection[1]),
|
||||
);
|
||||
assert_eq!(
|
||||
&ASTNode::SQLIdentifier(r#""simple id""#.to_string()),
|
||||
expr_from_projection(&select.projection[2]),
|
||||
);
|
||||
|
||||
verified_stmt(r#"CREATE TABLE "foo" ("bar" "int")"#);
|
||||
verified_stmt(r#"ALTER TABLE foo ADD CONSTRAINT "bar" PRIMARY KEY (baz)"#);
|
||||
//TODO verified_stmt(r#"UPDATE foo SET "bar" = 5"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_parens() {
|
||||
use self::ASTNode::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue