Re: SQL/JSON DEFAULT ON ERROR/ON EMPTY evaluation fail should rethrow error unconditionally

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SQL/JSON DEFAULT ON ERROR/ON EMPTY evaluation fail should rethrow error unconditionally
Date: 2026-09-16 03:01:05
Message-ID: CACJufxHAea2+DD+H6TNsm+VA8+RA5RvryH=MBtZu2sEWUzAeRg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 16, 2026 at 10:48 AM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
>
> Hi Jian,
>
>
> I haven't looked at the patch, but could you specify whether your
> patch fixes a live bug or is an improvement you found while working on
> the linked thread? I don't understand which is the case because your
> report doesn't have an example.
>

Apologies for the poor communication.

In src/test/regress/expected/sqljson_queryfuncs.out, we have lots of
ERROR: could not coerce ON ERROR expression (DEFAULT) to the RETURNING type

The comments in ExecInitJsonExpr also says that, for DEFAULT expr ON ERROR and
DEFAULT expr ON EMPTY, we evaluate the DEFAULT expression in an error-soft way
*but* rethrow the error, I assume the purpose is for better error message.

However, in the master branch, there are some cases where we do not
rethrow the soft error.
For example, I believe the query below should return an ERROR.
SELECT JSON_VALUE('"a"', '$' RETURNING int DEFAULT (('a' || (random()
* 0)::int)::int + 0) ON ERROR);

--
jian
https://www.enterprisedb.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-09-16 03:12:19 Re: PG19: two RI fast-path issues found while testing the batching revert
Previous Message Amit Langote 2026-09-16 02:50:06 Re: PG19 FK fast path: OOB write and missed FK checks during batched