Re: jsonb subscript operator returns null when key is fetched from table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: exe-dealer <exe-dealer(at)yandex(dot)ru>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: jsonb subscript operator returns null when key is fetched from table
Date: 2022-12-12 19:09:21
Message-ID: 2035559.1670872161@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2022-12-12 19:16:32 Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Previous Message David G. Johnston 2022-12-12 18:51:19 Re: jsonb subscript operator returns null when key is fetched from table