On Wed, Dec 6, 2023 at 10:02 PM Amit Langote <amitlangot...@gmail.com> wrote: > > Finally, I also fixed a couple of silly mistakes in 0003 around > transformJsonBehavior() and some further assorted tightening in the ON > ERROR / EMPTY expression coercion handling code. >
typo: + * If a soft-error occurs, it will be checked by EEOP_JSONEXPR_COECION_FINISH json_exists no RETURNING clause. so the following part in src/backend/parser/parse_expr.c can be removed? + else if (jsexpr->returning->typid != BOOLOID) + { + Node *coercion_expr; + CaseTestExpr *placeholder = makeNode(CaseTestExpr); + int location = exprLocation((Node *) jsexpr); + + /* + * We abuse CaseTestExpr here as placeholder to pass the + * result of evaluating JSON_EXISTS to the coercion + * expression. + */ + placeholder->typeId = BOOLOID; + placeholder->typeMod = -1; + placeholder->collation = InvalidOid; + + coercion_expr = + coerce_to_target_type(pstate, (Node *) placeholder, BOOLOID, + jsexpr->returning->typid, + jsexpr->returning->typmod, + COERCION_EXPLICIT, + COERCE_IMPLICIT_CAST, + location); + + if (coercion_expr == NULL) + ereport(ERROR, + (errcode(ERRCODE_CANNOT_COERCE), + errmsg("cannot cast type %s to %s", + format_type_be(BOOLOID), + format_type_be(jsexpr->returning->typid)), + parser_coercion_errposition(pstate, location, (Node *) jsexpr))); + + if (coercion_expr != (Node *) placeholder) + jsexpr->result_coercion = coercion_expr; + } Similarly, since JSON_EXISTS has no RETURNING clause, the following also needs to be refactored? + /* + * Disallow FORMAT specification in the RETURNING clause of JSON_EXISTS() + * and JSON_VALUE(). + */ + if (func->output && + (func->op == JSON_VALUE_OP || func->op == JSON_EXISTS_OP)) + { + JsonFormat *format = func->output->returning->format; + + if (format->format_type != JS_FORMAT_DEFAULT || + format->encoding != JS_ENC_DEFAULT) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("cannot specify FORMAT in RETURNING clause of %s", + func->op == JSON_VALUE_OP ? "JSON_VALUE()" : + "JSON_EXISTS()"), + parser_errposition(pstate, format->location)));