Re: ON ERROR in json_query and the like

From: Chapman Flack <jcflack(at)acm(dot)org>
To: Amit Langote <amitlangote09(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Markus Winand <markus(dot)winand(at)winand(dot)at>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ON ERROR in json_query and the like
Date: 2024-06-17 12:47:16
Message-ID: 66703054.6040109@acm.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 06/17/24 02:20, Amit Langote wrote:
>>> Apparently, the functions expect JSONB so that a cast is implied
>>> when providing TEXT. However, the errors during that cast are
>>> not subject to the ON ERROR clause.
>>>
>>> 17beta1=# SELECT JSON_QUERY('invalid', '$' NULL ON ERROR);
>>> ERROR: invalid input syntax for type json
>>> DETAIL: Token "invalid" is invalid.
>>> CONTEXT: JSON data, line 1: invalid
>>>
>>> Oracle DB and Db2 (LUW) both return NULL in that case.

I wonder, could prosupport rewriting be used to detect that the first
argument is supplied by a cast, and rewrite the expression to apply the
cast 'softly'? Or would that behavior be too magical?

Regards,
-Chap

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chapman Flack 2024-06-17 13:05:42 Re: SQL/JSON query functions context_item doc entry and type requirement
Previous Message Bharath Rupireddy 2024-06-17 12:25:04 Re: Introduce XID age and inactive timeout based replication slot invalidation