Skip to content

Commit 96f7c02

Browse files
lovasoaiffyio
andauthored
json_object('k' VALUE 'v') in postgres (#1547)
Co-authored-by: Ifeanyi Ubah <[email protected]>
1 parent b000738 commit 96f7c02

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/ast/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5528,6 +5528,8 @@ pub enum FunctionArgOperator {
55285528
Assignment,
55295529
/// function(arg1 : value1)
55305530
Colon,
5531+
/// function(arg1 VALUE value1)
5532+
Value,
55315533
}
55325534

55335535
impl fmt::Display for FunctionArgOperator {
@@ -5537,6 +5539,7 @@ impl fmt::Display for FunctionArgOperator {
55375539
FunctionArgOperator::RightArrow => f.write_str("=>"),
55385540
FunctionArgOperator::Assignment => f.write_str(":="),
55395541
FunctionArgOperator::Colon => f.write_str(":"),
5542+
FunctionArgOperator::Value => f.write_str("VALUE"),
55405543
}
55415544
}
55425545
}

src/parser/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11482,6 +11482,9 @@ impl<'a> Parser<'a> {
1148211482
}
1148311483

1148411484
fn parse_function_named_arg_operator(&mut self) -> Result<FunctionArgOperator, ParserError> {
11485+
if self.parse_keyword(Keyword::VALUE) {
11486+
return Ok(FunctionArgOperator::Value);
11487+
}
1148511488
let tok = self.next_token();
1148611489
match tok.token {
1148711490
Token::RArrow if self.dialect.supports_named_fn_args_with_rarrow_operator() => {

tests/sqlparser_postgres.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,19 @@ fn test_json() {
28242824
);
28252825
}
28262826

2827+
#[test]
2828+
fn test_fn_arg_with_value_operator() {
2829+
match pg().verified_expr("JSON_OBJECT('name' VALUE 'value')") {
2830+
Expr::Function(Function { args: FunctionArguments::List(FunctionArgumentList { args, .. }), .. }) => {
2831+
assert!(matches!(
2832+
&args[..],
2833+
&[FunctionArg::ExprNamed { operator: FunctionArgOperator::Value, .. }]
2834+
), "Invalid function argument: {:?}", args);
2835+
}
2836+
other => panic!("Expected: JSON_OBJECT('name' VALUE 'value') to be parsed as a function, but got {other:?}"),
2837+
}
2838+
}
2839+
28272840
#[test]
28282841
fn parse_json_table_is_not_reserved() {
28292842
// JSON_TABLE is not a reserved keyword in PostgreSQL, even though it is in SQL:2023

0 commit comments

Comments
 (0)