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 1p3k8I-00039T-4t for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2022 20:38:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3k8H-0004pk-1Y for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2022 20:38:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3je8-00056A-Q9 for pgsql-bugs@lists.postgresql.org; Fri, 09 Dec 2022 20:07:00 +0000 Received: from forward108p.mail.yandex.net ([77.88.28.116]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3je5-0005jv-5f for pgsql-bugs@lists.postgresql.org; Fri, 09 Dec 2022 20:06:59 +0000 Received: from myt5-073b6f151c16.qloud-c.yandex.net (myt5-073b6f151c16.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3ead:0:640:73b:6f15]) by forward108p.mail.yandex.net (Yandex) with ESMTP id 43FD0267BFF3 for ; Fri, 9 Dec 2022 23:06:52 +0300 (MSK) Received: from mail.yandex.ru (mail.yandex.ru [2.132.103.129]) by myt5-073b6f151c16.qloud-c.yandex.net (mxback/Yandex) with HTTP id i6hSGe0XO0U1-kXHfPERa; Fri, 09 Dec 2022 23:06:52 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1670616412; bh=g+NtQyWy6xXSfuc1zNFBZBaSOBjmqF4mi6sSjG7UrJE=; h=Message-Id:Date:Subject:To:From; b=wIkZHQbkmR70Av0czRQ+rRJ4xt2GrjBG7REzkq85XoM3X1l1ZqVPTbwiXFWKATAqV hnLAtV73dWeV/gC7VPlHziIc/5S+4NoeBlM/jjA6KuDPn/XRUz/mzaMeJCjh9RURwQ rvcpfBO2LKeFIxuH0puEjQk8yAMhoYAg0rIBiNUc= Authentication-Results: myt5-073b6f151c16.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Received: by cml2zkrna6iw5oui.myt.yp-c.yandex.net with HTTP; Fri, 09 Dec 2022 23:06:51 +0300 From: exe-dealer To: "pgsql-bugs@lists.postgresql.org" Subject: jsonb subscript operator returns null when key is fetched from table MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Sat, 10 Dec 2022 02:06:51 +0600 Message-Id: <205321670615953@mail.yandex.ru> Content-Transfer-Encoding: 8bit Content-Type: text/html; charset=utf-8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk
jsonb subscript operator returns null when key is fetched from table.
 
PostgreSQL 15.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924, 64-bit
 
WITH cte AS MATERIALIZED (SELECT 'foo' k, '{"foo":"bar"}'::jsonb j)
SELECT j[k], j[k || ''] FROM cte;
 
-- returns
-- null, "bar"
 
-- expected
-- "bar", "bar"