IS JSON predicate support for domain base type as JSON/JSONB/BYTEA/TEXT

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: IS JSON predicate support for domain base type as JSON/JSONB/BYTEA/TEXT
Date: 2025-11-18 15:43:13
Message-ID: CACJufxEk34DnJFG72CRsPPT4tsJL9arobX0tNPsn7yH28J=zQg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

src/backend/executor/execExpr.c

case T_JsonIsPredicate:
{
JsonIsPredicate *pred = (JsonIsPredicate *) node;
ExecInitExprRec((Expr *) pred->expr, state, resv, resnull);
scratch.opcode = EEOP_IS_JSON;
scratch.d.is_json.pred = pred;
ExprEvalPushStep(state, &scratch);
break;
}

gram.y:
a_expr IS json_predicate_type_constraint

the above shows the a_expr will be transformed and then evaluated.
The exprType type of a_expr as domain should work just fine.
The attached patch implements this, and it seems to be quite straightforward.
(extensive regress tests added)

CREATE DOMAIN jd1 AS JSON CHECK ((VALUE ->'a')::text <> '3');
CREATE DOMAIN jd2 AS JSONB CHECK ((VALUE ->'a') = '1'::jsonb);
CREATE DOMAIN jd4 AS bytea CHECK (VALUE <> '\x61');
SELECT NULL::jd1 IS JSON;
SELECT NULL::jd2 IS JSON;
SELECT NULL::jd4 IS JSON;

in the master, the above 3 IS JSON would return error,
with the attached patch, it will return NULL.

I checked the discussion links [1], but couldn’t find the reason domains aren’t
supported. I guess at that time, we didn't think about this issue.

[1] https://git.postgresql.org/cgit/postgresql.git/commit/?id=6ee30209a6f161d0a267a33f090c70c579c87c00

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

Attachment Content-Type Size
v1-0001-IS-JSON-predicate-work-with-domain-type.patch text/x-patch 23.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-11-18 15:54:32 Re: Consistently use the XLogRecPtrIsInvalid() macro
Previous Message Tomas Vondra 2025-11-18 15:40:41 Re: Performance issues with parallelism and LIMIT