Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json_object('k' VALUE 'v') in postgres #1547

Merged
merged 5 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5528,6 +5528,8 @@ pub enum FunctionArgOperator {
Assignment,
/// function(arg1 : value1)
Colon,
/// function(arg1 VALUE value1)
Value,
}

impl fmt::Display for FunctionArgOperator {
Expand All @@ -5537,6 +5539,7 @@ impl fmt::Display for FunctionArgOperator {
FunctionArgOperator::RightArrow => f.write_str("=>"),
FunctionArgOperator::Assignment => f.write_str(":="),
FunctionArgOperator::Colon => f.write_str(":"),
FunctionArgOperator::Value => f.write_str("VALUE"),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11478,6 +11478,9 @@ impl<'a> Parser<'a> {
}

fn parse_function_named_arg_operator(&mut self) -> Result<FunctionArgOperator, ParserError> {
if self.parse_keyword(Keyword::VALUE) {
return Ok(FunctionArgOperator::Value);
}
let tok = self.next_token();
match tok.token {
Token::RArrow if self.dialect.supports_named_fn_args_with_rarrow_operator() => {
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,19 @@ fn test_json() {
);
}

#[test]
fn test_fn_arg_with_value_operator() {
match pg().verified_expr("JSON_OBJECT('name' VALUE 'value')") {
Expr::Function(Function { args: FunctionArguments::List(FunctionArgumentList { args, .. }), .. }) => {
assert!(matches!(
&args[..],
&[FunctionArg::ExprNamed { operator: FunctionArgOperator::Value, .. }]
), "Invalid function argument: {:?}", args);
}
other => panic!("Expected: JSON_OBJECT('name' VALUE 'value') to be parsed as a function, but got {other:?}"),
}
}

#[test]
fn parse_json_table_is_not_reserved() {
// JSON_TABLE is not a reserved keyword in PostgreSQL, even though it is in SQL:2023
Expand Down