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 1xR5j2-00000000fn7-0pIj for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:44 +0000 Received: from localhost ([127.0.0.1]:44518 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR5iz-0000000AE0t-1hMY for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:59944) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR45l-00000009fhH-2KBX for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 08:54:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR45k-00000000LNX-3D1V for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 08:54:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=d6C+jhwmaa3OlVxFUmwhKDGKtfaq7rcraqsMnnfGNLo=; b=oskUwrJtvZVc55RIGEjDr6+oK8 hJSsbp+HhUOMKBeKqRp2oEL6Pu7QnkDvJ5/RW1IDMfdtzc8PgskUpvIDj7ZrMhBD30iU8c5mWcuSO 97voMP2JQxYR1DYA968OkqqH8sk/Fb/gbWrGVPKSmzpwFdcFkzCpCr6ICBHoXENrHf8Hr0vWFQDUZ z25IEjYKYvva95kzCZ1dzNsuBjptqnLZ/jWoyxX3eOWElYRuDlajgDkFev2iKy8ff3QICCxNtn17r 8BsaWc/DNAualA1mKnqFENEWfFF3BL2ZYbEao5rEKu9gC2gto+6fzH9z4eoWWW1pPqE5Zhr0cub89 2vpp9/+g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR45j-00000000x46-3ut3 for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 08:54:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR45j-00000002Vf7-0jGo for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 08:54:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19871: JSON_TABLE evaluates each PASSING argument once per column - a named variable $v gets different valu To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 08:53:50 +0000 Message-ID: <19871-e2aef51dcfd941f3@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19871 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 18.6 Operating system: Linux x86_64; platform-independent (reproduced ide Description: =20 **Description:** JSON_TABLE re-evaluates every PASSING expression for each output column (and once more for the row pattern). With a VOLATILE PASSING expression this is directly observable, and worse: **the same named variable `$v` read by two different columns =E2=80=94 or by the row-pattern filter and a column =E2= =80=94 gets different values within a single row**, so filter results and column values disagree. **Reproduction (self-contained SQL; verified on 18.6 and master):** ```sql -- M1: the SAME variable $v read by two columns differs: DROP SEQUENCE IF EXISTS s1, s2, s3, s4; CREATE SEQUENCE s1; SELECT * FROM JSON_TABLE(jsonb '[10]', '$[*]' PASSING nextval('s1') AS v COLUMNS (v1 int PATH '$v', v2 int PATH '$v', item int PATH '$')); -- v1 =3D 1, v2 =3D 2, item =3D 10 (two columns disagree about $v) SELECT last_value AS evaluations_count FROM s1; -- 4 (1 + 3 columns) -- M2: the row-pattern filter and a column read of $v disagree in ONE row: CREATE SEQUENCE s2; SELECT item, v_seen, (item =3D v_seen) AS consistent FROM JSON_TABLE(jsonb '[1,2,3]', '$[*] ? (@ =3D=3D $v)' PASSING nextval('s2') AS v COLUMNS (item int PATH '$', v_seen int PATH '$v')); -- consistent =3D f for every row (filter picked the row using one value of $v, -- the column reports another) -- control: immutable PASSING -> always consistent: SELECT item, v_seen, (item =3D v_seen) AS consistent FROM JSON_TABLE(jsonb '[1,2,3]', '$[*] ? (@ =3D=3D $v)' PASSING 2 AS v COLUMNS (item int PATH '$', v_seen int PATH '$v')); -- M3: even a single column evaluates PASSING twice: CREATE SEQUENCE s3; SELECT * FROM JSON_TABLE(jsonb '[10]', '$[*]' PASSING nextval('s3') AS v COLUMNS (v1 int PATH '$v')); SELECT last_value AS evaluations_count FROM s3; -- 2 -- control: a regular SQL/JSON function evaluates its PASSING once: CREATE SEQUENCE s4; SELECT JSON_QUERY(jsonb '[10]', '$[*]' PASSING nextval('s4') AS v RETURNING jsonb) AS q, nextval('s4') AS after; -- after =3D 2 =3D> one evaluation inside JSON_QUERY ``` **Actual results:** each PASSING expression is evaluated once per column plus once for the row pattern (last_value =3D 4 for three columns, 2 for on= e); the same `$v` yields different values across columns and between the filter and the columns. **Expected behavior:** PASSING expressions should be evaluated once per output row (as the regular SQL/JSON functions already do =E2=80=94 see the JSON_QUERY control), with every column and the row pattern seeing the same value. **Impact:** with VOLATILE/STABLE PASSING expressions the results are wrong within a row; side effects are multiplied by the column count.