Skip to content

Commit 5226b10

Browse files
committed
json_object('k' VALUE 'v') in postgres
Fixes apache#1545
1 parent 0fb2ef3 commit 5226b10

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/ast/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5462,6 +5462,8 @@ pub enum FunctionArgOperator {
54625462
Assignment,
54635463
/// function(arg1 : value1)
54645464
Colon,
5465+
/// function(arg1 VALUE value1)
5466+
Value,
54655467
}
54665468

54675469
impl fmt::Display for FunctionArgOperator {
@@ -5471,6 +5473,7 @@ impl fmt::Display for FunctionArgOperator {
54715473
FunctionArgOperator::RightArrow => f.write_str("=>"),
54725474
FunctionArgOperator::Assignment => f.write_str(":="),
54735475
FunctionArgOperator::Colon => f.write_str(":"),
5476+
FunctionArgOperator::Value => f.write_str("VALUE"),
54745477
}
54755478
}
54765479
}

src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11411,6 +11411,7 @@ impl<'a> Parser<'a> {
1141111411
Token::Colon if self.dialect.supports_named_fn_args_with_colon_operator() => {
1141211412
Ok(FunctionArgOperator::Colon)
1141311413
}
11414+
Token::Word(w) if w.value.to_uppercase() == "VALUE" => Ok(FunctionArgOperator::Value),
1141411415
_ => {
1141511416
self.prev_token();
1141611417
self.expected("argument operator", tok)

tests/sqlparser_postgres.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,19 @@ fn test_json() {
28122812
);
28132813
}
28142814

2815+
#[test]
2816+
fn test_json_object() {
2817+
match pg().verified_expr("JSON_OBJECT('name' VALUE 'value')") {
2818+
Expr::Function(Function { args: FunctionArguments::List(FunctionArgumentList { args, .. }), .. }) => {
2819+
assert!(matches!(
2820+
&args[..],
2821+
&[FunctionArg::ExprNamed { operator: FunctionArgOperator::Value, .. }]
2822+
));
2823+
}
2824+
other => panic!("Expected: JSON_OBJECT('name' VALUE 'value') to be parsed as a function, but got {other:?}"),
2825+
}
2826+
}
2827+
28152828
#[test]
28162829
fn parse_json_table_is_not_reserved() {
28172830
// JSON_TABLE is not a reserved keyword in PostgreSQL, even though it is in SQL:2023

0 commit comments

Comments
 (0)