mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-13 15:32:03 +00:00
Improve DELETE FROM parsing (4.4/4.4)
Store (and parse) `table_name: SQLObjectName` instead of `relation: Option<Box<ASTNode>>`, which can be an arbitrary expression. Also remove the `Option<>`: the table name is not optional in any dialects I'm familiar with. While the FROM keyword itself _is_ optional in some dialects, there are more things to implement for those dialects, see https://stackoverflow.com/a/4484271/1026
This commit is contained in:
parent
f5bd9c398f
commit
07790fe4c4
3 changed files with 14 additions and 33 deletions
|
@ -8,16 +8,10 @@ use sqlparser::sqltokenizer::*;
|
|||
|
||||
#[test]
|
||||
fn parse_delete_statement() {
|
||||
let sql: &str = "DELETE FROM 'table'";
|
||||
|
||||
match verified_stmt(&sql) {
|
||||
SQLStatement::SQLDelete { relation, .. } => {
|
||||
assert_eq!(
|
||||
Some(Box::new(ASTNode::SQLValue(Value::SingleQuotedString(
|
||||
"table".to_string()
|
||||
)))),
|
||||
relation
|
||||
);
|
||||
let sql = "DELETE FROM \"table\"";
|
||||
match verified_stmt(sql) {
|
||||
SQLStatement::SQLDelete { table_name, .. } => {
|
||||
assert_eq!(SQLObjectName(vec!["\"table\"".to_string()]), table_name);
|
||||
}
|
||||
|
||||
_ => assert!(false),
|
||||
|
@ -26,23 +20,17 @@ fn parse_delete_statement() {
|
|||
|
||||
#[test]
|
||||
fn parse_where_delete_statement() {
|
||||
let sql: &str = "DELETE FROM 'table' WHERE name = 5";
|
||||
|
||||
use self::ASTNode::*;
|
||||
use self::SQLOperator::*;
|
||||
|
||||
match verified_stmt(&sql) {
|
||||
let sql = "DELETE FROM foo WHERE name = 5";
|
||||
match verified_stmt(sql) {
|
||||
SQLStatement::SQLDelete {
|
||||
relation,
|
||||
table_name,
|
||||
selection,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(
|
||||
Some(Box::new(ASTNode::SQLValue(Value::SingleQuotedString(
|
||||
"table".to_string()
|
||||
)))),
|
||||
relation
|
||||
);
|
||||
assert_eq!(SQLObjectName(vec!["foo".to_string()]), table_name);
|
||||
|
||||
assert_eq!(
|
||||
SQLBinaryExpr {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue