BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select
Date
Msg-id 18356-a811d014209fd19c@postgresql.org
Whole thread Raw
Responses Re: BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select  (Ed Herrmann <ewherrmann@gmail.com>)
Re: BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18356
Logged by:          Ed Herrmann
Email address:      ewherrmann@gmail.com
PostgreSQL version: 16.0
Operating system:   Linux, MacOS
Description:

- Prior to v16, this statement would work for casting values of a k/v jsonb
pair to an integer:
                    SELECT id, mytdata.key, mytdata.value::integer
                    FROM my_table as myt,
                        jsonb_each_text(myt.data) as mytdata
                    WHERE mytdata.key IN ( SELECT key from week_key_table
)

- Where week_key_table stores keys such as "week01", "week02", and
"week03".
- And where the jsonb has some keys with alphanumeric values and some keys
with numeric values, such as: { "key_figure": "Volume", "week01": "0",
"week02": "0", "week03": "0"}

However as of v16, this same statement causes the error: 'invalid input
syntax for type double precision: "Volume"'. 

If the keys are specified directly, it will still work as normal, but thows
the casting error when the keys are being selected from another table.

Works:
                    SELECT id, mytdata.key, mytdata.value::integer
                    FROM my_table as myt,
                        jsonb_each_text(myt.data) as mytdata
                    WHERE mytdata.key IN ( "week01", "week02", "week03" )
Casting Error:
                    SELECT id, mytdata.key, mytdata.value::integer
                    FROM my_table as myt,
                        jsonb_each_text(myt.data) as mytdata
                    WHERE mytdata.key IN ( SELECT key from week_key_table )


pgsql-bugs by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: BUG #18349: ERROR: invalid DSA memory alloc request size 1811939328, CONTEXT: parallel worker
Next
From: Ed Herrmann
Date:
Subject: Re: BUG #18356: Casting values from jsonb_each_text does not respect WHERE filter with sub select