Hi folks,

Related to:
https://www.postgresql.org/message-id/03583FE7-A5EE-407C-907D-67865F3F8BFC%40gmail.com

When JSON_SERIALIZE() receives a jsonb-typed argument, the CaseTestExpr
placeholder used to set up coercion was unconditionally assigned JSONOID
(derived from the RETURNING format, which defaults to JS_FORMAT_JSON).
However, the executor passes the input argument value through directly
for JSON_SERIALIZE (see ExecInitExprRec in execExpr.c), so the actual
datum at runtime is jsonb, not json.  This type mismatch between the
placeholder and the runtime value caused the wrong coercion path to be
selected.

As Dirkjan mentioned, this results in confusing output.

Attached is a patch to address this, by deriving the placeholder type from
the
actual argument type via exprType(linitial(args)) when the constructor type
is
JSCTOR_JSON_SERIALIZE, rather than from returning->format->format_type.

Added a regression test to ensure JSONB is serialized correctly.

Cheers,

Matt

Attachment: 0001-Fix-JSON_SERIALIZE-coercion-placeholder-type-for-jso.patch
Description: Binary data

Reply via email to