Re: finish TODOs in to_json_is_immutable, to_jsonb_is_immutable also add tests on it

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: finish TODOs in to_json_is_immutable, to_jsonb_is_immutable also add tests on it
Date: 2026-03-10 06:31:50
Message-ID: CACJufxGQUW7iL3OzFVKEZ3=53HfD=XqOJV=xMgnyT8BRwb1fMg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 6, 2026 at 6:09 AM Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
> Here's a rework of this patch. It preserves the original signature of
> to_json{b}_is_immutable, and fixes some code duplication. It also uses
> the typecache to get composite info instead of calling relation_open,
> supports MultiRange types, and exits early if we made a recursive call
> (no need for json_categorize_type etc. in these cases).
>

In json_categorize_type, we have:
case INT2OID:
case INT4OID:
case INT8OID:
case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
getTypeOutputInfo(typoid, outfuncoid, &typisvarlena);
*tcategory = JSONTYPE_NUMERIC;

select proname, provolatile from pg_Proc where proname in ('int8out',
'int2out', 'int4out', 'float4out', 'float8out', 'numeric_out');

proname | provolatile
-------------+-------------
int2out | i
int4out | i
float4out | i
float8out | i
int8out | i
numeric_out | i
(6 rows)

Therefore for JSONTYPE_NUMERIC, has_mutable in json_check_mutability
will be false.
I slightly changed the `switch (tcategory)` handling in `json_check_mutability`.
Make the handling order the same as JsonTypeCategory.

Cosmetic change in src/test/regress/sql/sqljson.sql
--error
To
-- error

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

Attachment Content-Type Size
v6-0001-make-to_json-to_jsonb-immutability-test-complete.patch text/x-patch 24.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-03-10 06:43:53 Re: [PATCH] Support automatic sequence replication
Previous Message Michael Paquier 2026-03-10 06:18:58 Re: Add support for EXTRA_REGRESS_OPTS for meson