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 1pzeok-0002Du-Um for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 14:41:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pzeoj-0005JR-Sn for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 14:41:21 +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 1pzeoj-0005JI-IW for pgsql-general@lists.postgresql.org; Thu, 18 May 2023 14:41:21 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pzeog-000VJl-VO for pgsql-general@postgresql.org; Thu, 18 May 2023 14:41:20 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 491965C00B3; Thu, 18 May 2023 10:41:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 18 May 2023 10:41:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1684420878; x=1684507278; bh=SJkYbFqHp7WJQhXPIrlm61sM2dBHgi1UwyA 6iZGK1V8=; b=pmXous2+8HFXGPe4jwDyOllb8s11KapCYLKYiHAo+wZ3uCHotyN 43EKVO53K76CvK7+R8q3Rurr38LjwtsPLS0O90FJEMPcm4WA8g1zQpIKSs/pqHIk XN8tttaVMqzaKkoWZkfaPnM79XZp3iWu5YZk0mm6G6GkPXaG18eoCUZH5g1MhOnS gk8SXIqwMU4MT9jCaEg4/uqX3K8bQ//LqNj6XI5Sz/GeCqFwSDLTvKLxUBIUCiY7 Df/J3onnyhHV77cFqLrFIF6WsebLJH0TkDeiyrMHgAQThE+EdnTfM5bnpcmgJEjn 3HnZRzcOFLZZXOY/pAZ3xJkb3SAp3oaAVuw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684420878; x= 1684507278; bh=SJkYbFqHp7WJQhXPIrlm61sM2dBHgi1UwyA6iZGK1V8=; b=B RC2aPNpfpCxjQlk/WG0ucEqYpsvwYg50Yf7KFkh5tmddDA8Dt8h8lJzF00Fvpwjt 8muIOwfr/Pp6y+kC/XAbGYyXPfW4JKwnhxM/QRjTyMppPdUZ3KuEQkUugqavuanQ u5n+2NgU2Qxw6cs1ePPGDz+ERdTZgyqdvkRcZkiyWTWNjY8A4ds5Bp6B4u7h/YSP YxQIf/5C6pnCUXwpLA2S06yF/i/UlGCVca8KDMoLSTcMV7Bw7TF+i1yIRzXdiTGl cmcPov5z+4bVghz96BNtjOMIDR2no6MEHoN8o+XiXcflocKzC4+2lxUo3ageQ4JT ZEvBuUGsic+yXw255nrIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeifedgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeegffetgeeitdehudejtdefffekgfehheetkeevhedv udevtddttdegvdehieeitdenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgpd hrohhtrghmrghprdhnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 18 May 2023 10:41:17 -0400 (EDT) Message-ID: Date: Thu, 18 May 2023 07:41:16 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: JSONB operator unanticipated behaviour Content-Language: en-US To: Brian Mendoza , pgsql-general@postgresql.org References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/18/23 06:17, Brian Mendoza wrote: > Hello, > > I have encountered unanticipated behaviour with a JSONB operator, and > wanted to make sure I am not misunderstanding its intended use. > > When using the @> operator, I get this result. > > select '{"a": [1]}'::jsonb @> '{"a": []}'::jsonb; >  ?column? > ---------- >  t > (1 row) > > However, given the phrasing in the documentation, I would have expected > False. > > "Does the left JSON value contain the right JSON path/value entries at > the top level?" > > Particularly given the following: > > select '[1]'::jsonb = '[]'::jsonb; >  ?column? > ---------- >  f > (1 row) > > So the keys are the same, the values (when compared directly) are not, > but @> returns True. Have I misunderstood the usage of the operator? > > The above queries have been run on postgres 14, if that helps. Have you looked at the containment examples?: https://www.postgresql.org/docs/current/datatype-json.html#JSON-CONTAINMENT I'm thinking this: -- A top-level key and an empty object is contained: SELECT '{"foo": {"bar": "baz"}}'::jsonb @> '{"foo": {}}'::jsonb; and/or this "The general principle is that the contained object must match the containing object as to structure and data contents, possibly after discarding some non-matching array elements or object key/value pairs from the containing object. " applies. > > -- > Brian Mendoza > brian@rotamap.net > > Rotamap > www.rotamap.net > 020 7631 1555 > 3 Tottenham Street London W1T 2AF > Registered in England No. 04551928 -- Adrian Klaver adrian.klaver@aklaver.com