pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
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"
Date: Tue, 17 Nov 2026 10:41:01 -0500
Message-ID: <396124.1794930061@sss.pgh.pa.us> (raw)
In-Reply-To: <19910-24199f8af1474753@postgresql.org>
References: <19910-24199f8af1474753@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> 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

Attachments:

draft-fix-jsonb-flag-parsing.patch (text/x-diff, 3.0K) download diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.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 != 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 = JsonbIteratorNext(&it, &v, false)) == WJB_ELEM) { @@ -5640,12 +5642,15 @@ parse_jsonb_index_flags(Jsonb *jb) /* expect end of array now */ if (type != 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 = JsonbIteratorNext(&it, &v, false); if (type != 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/expected/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 bbb", "b": 123, "c": 456, "d": ERROR: wrong flag in flag array: "" HINT: Possible values are: "string", "numeric", "boolean", "key", and "all". select json_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 456, "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": 456, "d": true, "f": false, "g": null}'::json, '[]'); json_to_tsvector ------------------ diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/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 bbb", "b": 123, "c": 456, "d" ERROR: wrong flag in flag array: "" HINT: Possible values are: "string", "numeric", "boolean", "key", and "all". select jsonb_to_tsvector('english', '{"a": "aaa in bbb", "b": 123, "c": 456, "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": 456, "d": true, "f": false, "g": null}'::jsonb, '[]'); jsonb_to_tsvector -------------------

view thread (3+ messages)  latest in thread

Message-ID: <396124.1794930061@sss.pgh.pa.us>
Permalink:  ../396124.1794930061@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/396124.1794930061@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, hackerzheng666@gmail.com
  Subject: Re: BUG #19910: json(b)_to_tsvector() nested array filter gives internal error XX000 "unexpected end of flag array"
  In-Reply-To: <396124.1794930061@sss.pgh.pa.us>
  References: <19910-24199f8af1474753@postgresql.org> <396124.1794930061@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox