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 1kqJQq-0005s7-78 for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Dec 2020 17:20:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kqJQo-0004pT-8l for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Dec 2020 17:20:42 +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 1kqJQn-0004pM-Eq for pgsql-hackers@lists.postgresql.org; Fri, 18 Dec 2020 17:20:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kqJQh-0000RL-3X for pgsql-hackers@lists.postgresql.org; Fri, 18 Dec 2020 17:20:40 +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 0BIHKXg7163100 for ; Fri, 18 Dec 2020 12:20:34 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Weird special case in jsonb_concat() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <163098.1608312033.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 18 Dec 2020 12:20:33 -0500 Message-ID: <163099.1608312033@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk The discussion in [1] pointed out that the existing documentation for the "jsonb || jsonb" concatenation operator is far short of reality: it fails to acknowledge that the operator will accept any cases other than two jsonb array inputs or two jsonb object inputs. I'd about concluded that other cases were handled as if by wrapping non-array inputs in one-element arrays and then proceeding as for two arrays. That works for most scenarios, eg regression=3D# select '[3]'::jsonb || '{}'::jsonb; ?column? = ---------- [3, {}] (1 row) regression=3D# select '3'::jsonb || '[]'::jsonb; ?column? = ---------- [3] (1 row) regression=3D# select '3'::jsonb || '4'::jsonb; ?column? = ---------- [3, 4] (1 row) However, further experimentation found a case that fails: regression=3D# select '3'::jsonb || '{}'::jsonb; ERROR: invalid concatenation of jsonb objects I wonder what is the point of this weird exception, and whether whoever devised it can provide a concise explanation of what they think the full behavior of "jsonb || jsonb" is. Why isn't '[3, {}]' a reasonable result here, if the cases above are OK? regards, tom lane [1] https://www.postgresql.org/message-id/flat/0d72b76d-ca2b-4263-8888-d6d= fca861c51%40www.fastmail.com