From bc8fbe7bb3a3524c03141249c148765d8d476083 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 30 Nov 2026 18:44:07 -0500 Subject: [PATCH] doc: Note that JSON_TABLE can evaluate PASSING values repeatedly Columns can see different values of the same variable when the expression is volatile, which the documentation did not mention. Reported-by: chunling qin <303677365@qq.com> Discussion: https://postgr.es/m/19871-e2aef51dcfd941f3@postgresql.org --- doc/src/sgml/func/func-json.sgml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/src/sgml/func/func-json.sgml b/doc/src/sgml/func/func-json.sgml index ede39e7d024..2e2c8f3ea9d 100644 --- a/doc/src/sgml/func/func-json.sgml +++ b/doc/src/sgml/func/func-json.sgml @@ -3717,6 +3717,21 @@ where json_table_column is: is called the row pattern, which is used as the source for row values in the constructed view. + + + + A PASSING value can be + evaluated more than once, for the row pattern and again for each + column of each row. So if it is volatile, the same variable can have + different values within one row. To use a single value, compute it + in a sub-select in FROM, for example: + +SELECT jt.* FROM (SELECT random() AS r) AS s, + JSON_TABLE(jsonb '[1, 2]', '$[*]' PASSING s.r AS x + COLUMNS (a float8 PATH '$x', b float8 PATH '$x')) AS jt; + + + -- 2.37.1 (Apple Git-137.1)