Re: jsonb subscript operator returns null when key is fetched from table
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: exe-dealer <exe-dealer@yandex.ru>,
"pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2022-12-12T19:09:21Z
Lists: pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> Someone more experienced than I will need to actually do the debugging work
> though; hoping this reply will be seen by one of them.
Meh. Somebody was cavalier about detoasting the subscript:
jbvp = getKeyJsonValueFromContainer(container,
VARDATA(path[i]),
VARSIZE(path[i]) - VARHDRSZ,
NULL);
Neither VARDATA nor VARSIZE are valid to apply to an arbitrary datum.
Apparently, nobody has ever tested this with a subscript value fetched
straight from disk :-(. The given example accidentally works with
a NOT MATERIALIZED CTE because the whole thing gets stepwise folded
to constants. Likewise, the expression with || accidentally works
because concatenation always yields a non-toasted result.
regards, tom lane
Commits
-
Fix jsonb subscripting to cope with toasted subscript values.
- b0feda79fdf0 16.0 landed
- d79b76b10ed5 15.2 landed
- a18328bb3395 14.7 landed