mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
Add parsing for PostgreSQL math operators (#267)
This commit is contained in:
parent
2f71324c33
commit
926b03a31d
6 changed files with 171 additions and 6 deletions
|
@ -551,6 +551,65 @@ fn parse_prepare() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pg_bitwise_binary_ops() {
|
||||
let bitwise_ops = &[
|
||||
("#", BinaryOperator::PGBitwiseXor),
|
||||
(">>", BinaryOperator::PGBitwiseShiftRight),
|
||||
("<<", BinaryOperator::PGBitwiseShiftLeft),
|
||||
];
|
||||
|
||||
for (str_op, op) in bitwise_ops {
|
||||
let select = pg().verified_only_select(&format!("SELECT a {} b", &str_op));
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier(Ident::new("a"))),
|
||||
op: op.clone(),
|
||||
right: Box::new(Expr::Identifier(Ident::new("b"))),
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pg_unary_ops() {
|
||||
let pg_unary_ops = &[
|
||||
("~", UnaryOperator::PGBitwiseNot),
|
||||
("|/", UnaryOperator::PGSquareRoot),
|
||||
("||/", UnaryOperator::PGCubeRoot),
|
||||
("!!", UnaryOperator::PGPrefixFactorial),
|
||||
("@", UnaryOperator::PGAbs),
|
||||
];
|
||||
|
||||
for (str_op, op) in pg_unary_ops {
|
||||
let select = pg().verified_only_select(&format!("SELECT {} a", &str_op));
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::UnaryOp {
|
||||
op: op.clone(),
|
||||
expr: Box::new(Expr::Identifier(Ident::new("a"))),
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pg_postfix_factorial() {
|
||||
let postfix_factorial = &[("!", UnaryOperator::PGPostfixFactorial)];
|
||||
|
||||
for (str_op, op) in postfix_factorial {
|
||||
let select = pg().verified_only_select(&format!("SELECT a{}", &str_op));
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::UnaryOp {
|
||||
op: op.clone(),
|
||||
expr: Box::new(Expr::Identifier(Ident::new("a"))),
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn pg() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(PostgreSqlDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue