Обсуждение: [PATCH] Fix JSON_SERIALIZE() coercion placeholder type for jsonb input

Поиск
Список
Период
Сортировка

[PATCH] Fix JSON_SERIALIZE() coercion placeholder type for jsonb input

От
Matt Blewitt
Дата:
Hi folks,


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
Вложения

Re: [PATCH] Fix JSON_SERIALIZE() coercion placeholder type for jsonb input

От
Zsolt Parragi
Дата:
Hello!

This is a simple fix and it does what it says, it looks good to me.

I did test it with a few more queries and compared it against master,
all looks good.



Re: [PATCH] Fix JSON_SERIALIZE() coercion placeholder type for jsonb input

От
Matt Blewitt
Дата:
Hi Zsolt,

Thanks for testing that out and confirming it looks good against master. Submitted to commitfest for further review and integration consideration.

Matt

On Fri, Mar 13, 2026 at 11:20 PM Zsolt Parragi <zsolt.parragi@percona.com> wrote:
Hello!

This is a simple fix and it does what it says, it looks good to me.

I did test it with a few more queries and compared it against master,
all looks good.