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 1nizUM-0001CG-8m for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2022 14:14:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nizUL-0000hr-60 for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Apr 2022 14:14:53 +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 1nizUK-0000hi-Sw for pgsql-hackers@lists.postgresql.org; Mon, 25 Apr 2022 14:14:52 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nizUH-000557-TB for pgsql-hackers@lists.postgresql.org; Mon, 25 Apr 2022 14:14:51 +0000 Received: (Authenticated sender: adsend@dunslane.net) by mail.gandi.net (Postfix) with ESMTPSA id 52C306000F; Mon, 25 Apr 2022 14:14:42 +0000 (UTC) Content-Type: multipart/mixed; boundary="------------rY2y6m0qCeEK7sph0uq047Id" Message-ID: <2a30c387-3c59-59a2-cd24-e85b7ab17e80@dunslane.net> Date: Mon, 25 Apr 2022 10:14:41 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: json_object returning jsonb reuslt different from returning json, returning text Content-Language: en-US To: alias , PostgreSQL Hackers References: From: Andrew Dunstan In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------rY2y6m0qCeEK7sph0uq047Id Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2022-04-25 Mo 01:19, alias wrote: > > seems it's a bug around value 0. > > SELECT JSON_OBJECTAGG(k: v ABSENT ON NULL WITH UNIQUE KEYS RETURNING > jsonb) > FROM (VALUES (1, 1), (10, NULL),(4, null), (5, null),(6, null),(2, 2)) > foo(k, v); > return: > {"1": 1, "2": 2} > > SELECT JSON_OBJECTAGG(k: v ABSENT ON NULL WITH UNIQUE KEYS RETURNING > jsonb) > FROM (VALUES (1, 1), (0, NULL),(4, null), (5, null),(6, null),(2, 2)) > foo(k, v); > > return >  {"0": null, "1": 1, "2": 2} Thanks for the report. I don't think there's anything special about '0' except that it sorts first. There appears to be a bug in the uniquefying code where the first item(s) have nulls. The attached appears to fix it. Please test and see if you can break it. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com --------------rY2y6m0qCeEK7sph0uq047Id Content-Type: text/x-patch; charset=UTF-8; name="jsonb-uniquefy-fix.patch" Content-Disposition: attachment; filename="jsonb-uniquefy-fix.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3V0aWxzL2FkdC9qc29uYl91dGlsLmMgYi9zcmMv YmFja2VuZC91dGlscy9hZHQvanNvbmJfdXRpbC5jCmluZGV4IGFhMTUxYTUzZDYuLjIxZDg3 NGMwOTggMTAwNjQ0Ci0tLSBhL3NyYy9iYWNrZW5kL3V0aWxzL2FkdC9qc29uYl91dGlsLmMK KysrIGIvc3JjL2JhY2tlbmQvdXRpbHMvYWR0L2pzb25iX3V0aWwuYwpAQCAtMTk1OSw4ICsx OTU5LDE4IEBAIHVuaXF1ZWlmeUpzb25iT2JqZWN0KEpzb25iVmFsdWUgKm9iamVjdCwgYm9v bCB1bmlxdWVfa2V5cywgYm9vbCBza2lwX251bGxzKQogCiAJaWYgKGhhc05vblVuaXEgfHwg c2tpcF9udWxscykKIAl7Ci0JCUpzb25iUGFpciAgKnB0ciA9IG9iamVjdC0+dmFsLm9iamVj dC5wYWlycyArIDEsCi0JCQkJICAgKnJlcyA9IG9iamVjdC0+dmFsLm9iamVjdC5wYWlyczsK KwkJSnNvbmJQYWlyICAqcHRyLCAqcmVzOworCisJCXdoaWxlIChza2lwX251bGxzICYmIG9i amVjdC0+dmFsLm9iamVjdC5uUGFpcnMgPiAwICYmCisJCQkgICBvYmplY3QtPnZhbC5vYmpl Y3QucGFpcnMtPnZhbHVlLnR5cGUgPT0gamJ2TnVsbCkKKwkJeworCQkJLyogSWYgc2tpcF9u dWxscyBpcyB0cnVlLCByZW1vdmUgbGVhZGluZyBpdGVtcyB3aXRoIG51bGwgKi8KKwkJCW9i amVjdC0+dmFsLm9iamVjdC5wYWlycysrOworCQkJb2JqZWN0LT52YWwub2JqZWN0Lm5QYWly cy0tOworCQl9CisKKwkJcHRyID0gb2JqZWN0LT52YWwub2JqZWN0LnBhaXJzICsgMTsKKwkJ cmVzID0gb2JqZWN0LT52YWwub2JqZWN0LnBhaXJzOwogCiAJCXdoaWxlIChwdHIgLSBvYmpl Y3QtPnZhbC5vYmplY3QucGFpcnMgPCBvYmplY3QtPnZhbC5vYmplY3QublBhaXJzKQogCQl7 Cg== --------------rY2y6m0qCeEK7sph0uq047Id--