mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
add support for postgres composite types (#466)
* add support for postgres composite types Signed-off-by: password <rbalajis25@gmail.com> * fix composite test for bigdecimal feature Signed-off-by: password <rbalajis25@gmail.com>
This commit is contained in:
parent
6b2fc8102f
commit
ed86c6d53d
3 changed files with 81 additions and 1 deletions
|
@ -1334,6 +1334,67 @@ fn test_json() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_composite_value() {
|
||||
let sql = "SELECT (on_hand.item).name FROM on_hand WHERE (on_hand.item).price > 9";
|
||||
let select = pg().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::CompositeAccess {
|
||||
key: Ident::new("name"),
|
||||
expr: Box::new(Expr::Nested(Box::new(Expr::CompoundIdentifier(vec![
|
||||
Ident::new("on_hand"),
|
||||
Ident::new("item")
|
||||
]))))
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
|
||||
#[cfg(feature = "bigdecimal")]
|
||||
let num: Expr = Expr::Value(Value::Number(bigdecimal::BigDecimal::from(9), false));
|
||||
#[cfg(not(feature = "bigdecimal"))]
|
||||
let num: Expr = Expr::Value(Value::Number("9".to_string(), false));
|
||||
assert_eq!(
|
||||
select.selection,
|
||||
Some(Expr::BinaryOp {
|
||||
left: Box::new(Expr::CompositeAccess {
|
||||
key: Ident::new("price"),
|
||||
expr: Box::new(Expr::Nested(Box::new(Expr::CompoundIdentifier(vec![
|
||||
Ident::new("on_hand"),
|
||||
Ident::new("item")
|
||||
]))))
|
||||
}),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(num)
|
||||
})
|
||||
);
|
||||
|
||||
let sql = "SELECT (information_schema._pg_expandarray(ARRAY['i', 'i'])).n";
|
||||
let select = pg().verified_only_select(sql);
|
||||
assert_eq!(
|
||||
SelectItem::UnnamedExpr(Expr::CompositeAccess {
|
||||
key: Ident::new("n"),
|
||||
expr: Box::new(Expr::Nested(Box::new(Expr::Function(Function {
|
||||
name: ObjectName(vec![
|
||||
Ident::new("information_schema"),
|
||||
Ident::new("_pg_expandarray")
|
||||
]),
|
||||
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Array(
|
||||
Array {
|
||||
elem: vec![
|
||||
Expr::Value(Value::SingleQuotedString("i".to_string())),
|
||||
Expr::Value(Value::SingleQuotedString("i".to_string())),
|
||||
],
|
||||
named: true
|
||||
}
|
||||
)))],
|
||||
over: None,
|
||||
distinct: false,
|
||||
}))))
|
||||
}),
|
||||
select.projection[0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_comments() {
|
||||
match pg().verified_stmt("COMMENT ON COLUMN tab.name IS 'comment'") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue