Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p4oCA-0001hR-9Y for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Dec 2022 19:10:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p4oBA-0007pr-D0 for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Dec 2022 19:09:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p4oBA-0007ph-55 for pgsql-bugs@lists.postgresql.org; Mon, 12 Dec 2022 19:09:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p4oB3-0001mL-IB for pgsql-bugs@lists.postgresql.org; Mon, 12 Dec 2022 19:09:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2BCJ9L3G2035560; Mon, 12 Dec 2022 14:09:21 -0500 From: Tom Lane To: "David G. Johnston" cc: exe-dealer , "pgsql-bugs@lists.postgresql.org" Subject: Re: jsonb subscript operator returns null when key is fetched from table In-reply-to: References: <205321670615953@mail.yandex.ru> Comments: In-reply-to "David G. Johnston" message dated "Mon, 12 Dec 2022 11:51:19 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2035558.1670872161.1@sss.pgh.pa.us> Date: Mon, 12 Dec 2022 14:09:21 -0500 Message-ID: <2035559.1670872161@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" 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