mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
feat: Support escaped string literals (PostgreSQL) (#502)
* feat: Support escaped string literals (PostgreSQL) Signed-off-by: Dmitry Patsura <talk@dmtry.me> * lint * escape ', \r, \t * Update src/ast/value.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * Update src/tokenizer.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * test: two slashes * remove dead code * test: parsing error * support generic dialect too (for DF) Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
4070f3ec6e
commit
2c0886d9fe
4 changed files with 167 additions and 0 deletions
|
@ -1467,3 +1467,44 @@ fn pg_and_generic() -> TestedDialects {
|
|||
dialects: vec![Box::new(PostgreSqlDialect {}), Box::new(GenericDialect {})],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_escaped_literal_string() {
|
||||
let sql =
|
||||
r#"SELECT E's1 \n s1', E's2 \\n s2', E's3 \\\n s3', E's4 \\\\n s4', E'\'', E'foo \\'"#;
|
||||
let select = pg_and_generic().verified_only_select(sql);
|
||||
assert_eq!(6, select.projection.len());
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("s1 \n s1".to_string())),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("s2 \\n s2".to_string())),
|
||||
expr_from_projection(&select.projection[1])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("s3 \\\n s3".to_string())),
|
||||
expr_from_projection(&select.projection[2])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("s4 \\\\n s4".to_string())),
|
||||
expr_from_projection(&select.projection[3])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("'".to_string())),
|
||||
expr_from_projection(&select.projection[4])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Value(Value::EscapedStringLiteral("foo \\".to_string())),
|
||||
expr_from_projection(&select.projection[5])
|
||||
);
|
||||
|
||||
let sql = r#"SELECT E'\'"#;
|
||||
assert_eq!(
|
||||
pg_and_generic()
|
||||
.parse_sql_statements(sql)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"sql parser error: Unterminated encoded string literal at Line: 1, Column 8"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue