adamchainz commented on code in PR #2001:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2001#discussion_r2300864648


##########
tests/sqlparser_postgres.rs:
##########
@@ -3363,6 +3387,68 @@ fn test_fn_arg_with_value_operator() {
     }
 }
 
+#[test]
+fn json_object_with_null_clause() {
+    match pg().verified_expr("JSON_OBJECT('name' VALUE 'value' NULL ON NULL)") 
{
+        Expr::Function(Function { args: 
FunctionArguments::List(FunctionArgumentList { args, clauses, .. }), .. }) => {
+            assert!(matches!(
+                &args[..],
+                &[FunctionArg::ExprNamed { operator: 
FunctionArgOperator::Value, .. }]
+            ), "Invalid function argument: {args:?}");
+            assert_eq!(
+                clauses,
+                
vec![FunctionArgumentClause::JsonNullClause(JsonNullClause::NullOnNull)],
+                "Expected: NULL ON NULL to be parsed as a null treatment 
clause, but got {clauses:?}"
+            );
+        }
+        other => panic!("Expected: JSON_OBJECT('name' VALUE 'value' NULL ON 
NULL) to be parsed as a function, but got {other:?}"),
+    }
+}
+
+#[test]
+fn json_object_with_returning_clause() {
+    match pg().verified_expr("JSON_OBJECT('name' VALUE 'value' RETURNING 
JSONB)") {
+        Expr::Function(Function { args: 
FunctionArguments::List(FunctionArgumentList { args, clauses, .. }), .. }) => {
+            assert!(matches!(
+                &args[..],
+                &[FunctionArg::ExprNamed { operator: 
FunctionArgOperator::Value, .. }]
+            ), "Invalid function argument: {args:?}");
+            assert_eq!(
+                clauses,
+                
vec![FunctionArgumentClause::JsonReturningClause(JsonReturningClause {
+                    data_type: DataType::JSONB
+                })],
+                "Expected: RETURNING JSONB to be parsed as a returning clause, 
but got {clauses:?}"
+            );
+        }
+        other => panic!("Expected: JSON_OBJECT('name' VALUE 'value' RETURNING 
jsonb) to be parsed as a function, but got {other:?}"),
+    }
+}
+
+#[test]
+fn json_object_only_returning_clause() {
+    match pg().verified_expr("JSON_OBJECT(RETURNING JSONB)") {
+        Expr::Function(Function {
+            args: FunctionArguments::List(FunctionArgumentList { args, 
clauses, .. }),
+            ..
+        }) => {
+            assert!(args.is_empty(), "Expected no arguments, got: {args:?}");
+            assert_eq!(
+                clauses,
+                vec![FunctionArgumentClause::JsonReturningClause(
+                    JsonReturningClause {
+                        data_type: DataType::JSONB
+                    }
+                )],
+                "Expected: RETURNING JSONB to be parsed as a returning clause, 
but got {clauses:?}"
+            );
+        }
+        other => panic!(
+            "Expected: JSON_OBJECT(RETURNING jsonb) to be parsed as a 
function, but got {other:?}"
+        ),
+    }
+}

Review Comment:
   Done!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to