Support MySQL ROWS syntax for VALUES (#737)

* Adapt VALUES to MySQL dialect

* Update src/ast/query.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* remove *requirement* for ROW

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
Aljaž Mur Eržen 2022-12-01 15:46:55 +01:00 committed by GitHub
parent faf75b7161
commit 8e1c90c0d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 35 deletions

View file

@ -88,7 +88,9 @@ fn parse_insert_values() {
assert_eq!(column, &Ident::new(expected_columns[index].clone()));
}
match &*source.body {
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), expected_rows),
SetExpr::Values(Values { rows, .. }) => {
assert_eq!(rows.as_slice(), expected_rows)
}
_ => unreachable!(),
}
}
@ -460,6 +462,7 @@ fn parse_top_level() {
verified_stmt("(SELECT 1)");
verified_stmt("((SELECT 1))");
verified_stmt("VALUES (1)");
verified_stmt("VALUES ROW(1, true, 'a'), ROW(2, false, 'b')");
}
#[test]
@ -4268,6 +4271,7 @@ fn parse_values() {
verified_stmt("SELECT * FROM (VALUES (1), (2), (3))");
verified_stmt("SELECT * FROM (VALUES (1), (2), (3)), (VALUES (1, 2, 3))");
verified_stmt("SELECT * FROM (VALUES (1)) UNION VALUES (1)");
verified_stmt("SELECT * FROM (VALUES ROW(1, true, 'a'), ROW(2, false, 'b')) AS t (a, b, c)");
}
#[test]
@ -5608,11 +5612,14 @@ fn parse_merge() {
MergeClause::NotMatched {
predicate: None,
columns: vec![Ident::new("A"), Ident::new("B"), Ident::new("C")],
values: Values(vec![vec![
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("A")]),
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("B")]),
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("C")]),
]]),
values: Values {
explicit_row: false,
rows: vec![vec![
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("A")]),
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("B")]),
Expr::CompoundIdentifier(vec![Ident::new("stg"), Ident::new("C")]),
]]
},
},
MergeClause::MatchedUpdate {
predicate: Some(Expr::BinaryOp {