mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
Support ?-based jsonb operators in Postgres (#1242)
Co-authored-by: Andrew Repp <arepp@cloudflare.com>
This commit is contained in:
parent
bafaa914b0
commit
4aa37a46a9
5 changed files with 125 additions and 13 deletions
|
@ -2401,6 +2401,51 @@ fn test_json() {
|
|||
},
|
||||
select.selection.unwrap(),
|
||||
);
|
||||
|
||||
let sql = r#"SELECT info FROM orders WHERE info ? 'b'"#;
|
||||
let select = pg().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("info"))),
|
||||
op: BinaryOperator::Question,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString("b".to_string()))),
|
||||
},
|
||||
select.selection.unwrap(),
|
||||
);
|
||||
|
||||
let sql = r#"SELECT info FROM orders WHERE info ?& ARRAY['b', 'c']"#;
|
||||
let select = pg().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("info"))),
|
||||
op: BinaryOperator::QuestionAnd,
|
||||
right: Box::new(Expr::Array(Array {
|
||||
elem: vec![
|
||||
Expr::Value(Value::SingleQuotedString("b".to_string())),
|
||||
Expr::Value(Value::SingleQuotedString("c".to_string()))
|
||||
],
|
||||
named: true
|
||||
}))
|
||||
},
|
||||
select.selection.unwrap(),
|
||||
);
|
||||
|
||||
let sql = r#"SELECT info FROM orders WHERE info ?| ARRAY['b', 'c']"#;
|
||||
let select = pg().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("info"))),
|
||||
op: BinaryOperator::QuestionPipe,
|
||||
right: Box::new(Expr::Array(Array {
|
||||
elem: vec![
|
||||
Expr::Value(Value::SingleQuotedString("b".to_string())),
|
||||
Expr::Value(Value::SingleQuotedString("c".to_string()))
|
||||
],
|
||||
named: true
|
||||
}))
|
||||
},
|
||||
select.selection.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue