pgsql: Fix parsing mode tracking when recycling datetime format cache e

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix parsing mode tracking when recycling datetime format cache e
Date: 2026-11-20 06:22:27
Message-ID: E1xUI0w-00000000Tna-1Ayb@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix parsing mode tracking when recycling datetime format cache entries

JSONPath datetime() could accept invalid format strings depending on
earlier datetime formatting operations in the same session. For example,
a format containing an unquoted "z" separator could be accepted after
to_char() had used it, although SQL/JSON standard mode prohibited it.

The cause was that DCH_cache_getnew() did not update the std flag when
recycling a cache entry. Since cache lookups matched both the format
string and std, a format parsed in one mode could be reused in the other.

Fix this by setting std when recycling an entry, as already done when
allocating a new one.

Backpatch to all supported versions.

Reported-by: Michael Malis <malis(at)pgrust(dot)com>
Author: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
Reviewed-by: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/19594-5d9bdc019e3f7f6e@postgresql.org
Backpatch-through: 15

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/04185e794bc7a624bce7b0fdf97e9b29086ba610

Modified Files
--------------
src/backend/utils/adt/formatting.c | 1 +
src/test/regress/expected/jsonb_jsonpath.out | 22 ++++++++++++++++++++++
src/test/regress/sql/jsonb_jsonpath.sql | 12 ++++++++++++
3 files changed, 35 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-11-20 09:23:44 pgsql: doc: Standardise cleartext and plain text terms
Previous Message Fujii Masao 2026-11-20 06:15:34 pgsql: psql: Fix out-of-bounds reads in prompt expansion