mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
update on conflict method (#735)
This commit is contained in:
parent
a422116b89
commit
042effdf14
3 changed files with 94 additions and 18 deletions
|
@ -1117,10 +1117,13 @@ fn parse_pg_on_conflict() {
|
|||
} => {
|
||||
assert_eq!(vec![Ident::from("did")], conflict_target);
|
||||
assert_eq!(
|
||||
OnConflictAction::DoUpdate(vec![Assignment {
|
||||
id: vec!["dname".into()],
|
||||
value: Expr::CompoundIdentifier(vec!["EXCLUDED".into(), "dname".into()])
|
||||
},]),
|
||||
OnConflictAction::DoUpdate(DoUpdate {
|
||||
assignments: vec![Assignment {
|
||||
id: vec!["dname".into()],
|
||||
value: Expr::CompoundIdentifier(vec!["EXCLUDED".into(), "dname".into()])
|
||||
},],
|
||||
selection: None
|
||||
}),
|
||||
action
|
||||
);
|
||||
}
|
||||
|
@ -1147,16 +1150,22 @@ fn parse_pg_on_conflict() {
|
|||
conflict_target
|
||||
);
|
||||
assert_eq!(
|
||||
OnConflictAction::DoUpdate(vec![
|
||||
Assignment {
|
||||
id: vec!["dname".into()],
|
||||
value: Expr::CompoundIdentifier(vec!["EXCLUDED".into(), "dname".into()])
|
||||
},
|
||||
Assignment {
|
||||
id: vec!["area".into()],
|
||||
value: Expr::CompoundIdentifier(vec!["EXCLUDED".into(), "area".into()])
|
||||
},
|
||||
]),
|
||||
OnConflictAction::DoUpdate(DoUpdate {
|
||||
assignments: vec![
|
||||
Assignment {
|
||||
id: vec!["dname".into()],
|
||||
value: Expr::CompoundIdentifier(vec![
|
||||
"EXCLUDED".into(),
|
||||
"dname".into()
|
||||
])
|
||||
},
|
||||
Assignment {
|
||||
id: vec!["area".into()],
|
||||
value: Expr::CompoundIdentifier(vec!["EXCLUDED".into(), "area".into()])
|
||||
},
|
||||
],
|
||||
selection: None
|
||||
}),
|
||||
action
|
||||
);
|
||||
}
|
||||
|
@ -1182,6 +1191,43 @@ fn parse_pg_on_conflict() {
|
|||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt(
|
||||
"INSERT INTO distributors (did, dname, dsize) \
|
||||
VALUES (5, 'Gizmo Transglobal', 1000), (6, 'Associated Computing, Inc', 1010) \
|
||||
ON CONFLICT(did) \
|
||||
DO UPDATE SET dname = $1 WHERE dsize > $2",
|
||||
);
|
||||
match stmt {
|
||||
Statement::Insert {
|
||||
on:
|
||||
Some(OnInsert::OnConflict(OnConflict {
|
||||
conflict_target,
|
||||
action,
|
||||
})),
|
||||
..
|
||||
} => {
|
||||
assert_eq!(vec![Ident::from("did")], conflict_target);
|
||||
assert_eq!(
|
||||
OnConflictAction::DoUpdate(DoUpdate {
|
||||
assignments: vec![Assignment {
|
||||
id: vec!["dname".into()],
|
||||
value: Expr::Value(Value::Placeholder("$1".to_string()))
|
||||
},],
|
||||
selection: Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident {
|
||||
value: "dsize".to_string(),
|
||||
quote_style: None
|
||||
})),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(Expr::Value(Value::Placeholder("$2".to_string())))
|
||||
})
|
||||
}),
|
||||
action
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue