Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTLIy-00000000H0V-15HE for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 15:41:09 +0000 Received: from localhost ([127.0.0.1]:37796 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTLIx-00000005qZL-2YHn for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 15:41:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:52508) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTLIx-00000005qZ1-1VDm for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:41:07 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTLIu-00000000ASK-3yNJ for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 15:41:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 6AHFf15g396125; Tue, 17 Nov 2026 10:41:01 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 sss.pgh.pa.us 6AHFf15g396125 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sss.pgh.pa.us; s=default; t=1794930061; bh=6ODhMONvvpkT/iofm0SM2ArQySbMLP6uuguRrcKZM4k=; h=From:To:cc:Subject:In-reply-to:References:Date:From; b=HcT10oDzdAAtScomUug0A0xVvW6jIzP/V2Di9l0lL5sdWZjJEJXIL7m1SDYj6jHf8 AUehzM3eu8Jq7NVUVLPyBqNGnNlo8YsqESNuA9mYylDOEJCp3uk2RNA/6t8lOmpWAk f2DasD8IxwWqpBLUSqQuWF6QNw65z7+JJf6TZgP4= From: Tom Lane To: hackerzheng666@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19910: json(b)_to_tsvector() nested array filter gives internal error XX000 "unexpected end of flag array" In-reply-to: <19910-24199f8af1474753@postgresql.org> References: <19910-24199f8af1474753@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 17 Nov 2026 05:03:22 +0000" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <396041.1794929981.0@sss.pgh.pa.us> Date: Tue, 17 Nov 2026 10:41:01 -0500 Message-ID: <396124.1794930061@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <396041.1794929981.1@sss.pgh.pa.us> PG Bug reporting form writes: > A filter argument that contains a nested array is rejected with an > internal-error message (SQLSTATE XX000, raised by elog) instead of the > invalid_parameter_value error that every other bad filter gets: Hmm, yeah. The tests in this code are actually correct, but not a lot of thought was put into the error messages. Need something like the attached. (I think the last elog() call is indeed unreachable, but maybe I'm wrong?) regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="draft-fix-jsonb-flag-parsing.patch"; charset="us-ascii" Content-ID: <396041.1794929981.2@sss.pgh.pa.us> Content-Description: draft-fix-jsonb-flag-parsing.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jso= nfuncs.c index 438f9f23ee0..25f14f92370 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -5604,8 +5604,10 @@ parse_jsonb_index_flags(Jsonb *jb) * chosen the same as jsonb_typeof uses. */ if (type !=3D WJB_BEGIN_ARRAY) - ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("wrong flag type, only arrays and scalars are allowed"))); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("incorrect flag structure"), + errdetail("Flags argument must be a string or array of strings."))); = while ((type =3D JsonbIteratorNext(&it, &v, false)) =3D=3D WJB_ELEM) { @@ -5640,12 +5642,15 @@ parse_jsonb_index_flags(Jsonb *jb) = /* expect end of array now */ if (type !=3D WJB_END_ARRAY) - elog(ERROR, "unexpected end of flag array"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("incorrect flag structure"), + errdetail("Flags argument must be a string or array of strings."))); = /* get final WJB_DONE and free iterator */ type =3D JsonbIteratorNext(&it, &v, false); if (type !=3D WJB_DONE) - elog(ERROR, "unexpected end of flag array"); + elog(ERROR, "unexpected items after flag array"); = return flags; } diff --git a/src/test/regress/expected/json.out b/src/test/regress/expecte= d/json.out index 5411003e2e6..461c8781752 100644 --- a/src/test/regress/expected/json.out +++ b/src/test/regress/expected/json.out @@ -2785,7 +2785,8 @@ select json_to_tsvector('english', '{"a": "aaa in bb= b", "b": 123, "c": 456, "d": ERROR: wrong flag in flag array: "" HINT: Possible values are: "string", "numeric", "boolean", "key", and "a= ll". select json_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 45= 6, "d": true, "f": false, "g": null}'::json, '{}'); -ERROR: wrong flag type, only arrays and scalars are allowed +ERROR: incorrect flag structure +DETAIL: Flags argument must be a string or array of strings. select json_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 45= 6, "d": true, "f": false, "g": null}'::json, '[]'); json_to_tsvector = ------------------ diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expect= ed/jsonb.out index efcbcddc1b3..1e8bdd08168 100644 --- a/src/test/regress/expected/jsonb.out +++ b/src/test/regress/expected/jsonb.out @@ -5741,7 +5741,8 @@ select jsonb_to_tsvector('english', '{"a": "aaa in b= bb", "b": 123, "c": 456, "d" ERROR: wrong flag in flag array: "" HINT: Possible values are: "string", "numeric", "boolean", "key", and "a= ll". select jsonb_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 4= 56, "d": true, "f": false, "g": null}'::jsonb, '{}'); -ERROR: wrong flag type, only arrays and scalars are allowed +ERROR: incorrect flag structure +DETAIL: Flags argument must be a string or array of strings. select jsonb_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 4= 56, "d": true, "f": false, "g": null}'::jsonb, '[]'); jsonb_to_tsvector = ------------------- ------- =_aaaaaaaaaa0--