Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVRf8-000CrN-GJ for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Aug 2023 07:06:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qVRf7-001kQA-5d for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Aug 2023 07:06:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVRf6-001kPu-S8 for pgsql-hackers@lists.postgresql.org; Mon, 14 Aug 2023 07:06:49 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qVRf0-0002Pm-Kq for pgsql-hackers@postgresql.org; Mon, 14 Aug 2023 07:06:47 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1ba5cda3530so3133253fac.3 for ; Mon, 14 Aug 2023 00:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691996802; x=1692601602; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=U0QTEI38kWU+1C4vkrjNkWzQdHCYPiEyuFiG5Wveegg=; b=Q8Baj6CUbaCHBrrJKEPjvpLkiRm/eXbsA9J534mBOyaHjYgpX1iZWZTQW43wlwQgfe Mq4vAwDzfVkF20rDjwk+3dDy9MyedhVpPCCji6adfwV6sYoikKzrB550n0JbT/JTTHFu 0GGYcWDHTj+rf5fSBhq2ewEGA97CjzI7afCzfV3zBocNPg2bmlaEHiMR9DfWTvBX7uz2 d9IEIVK0cTI5CrVTY9GaNPZdvAIW6edcFKaArcarimWWs9m5yYEvmArTFvFYQkmEwlaP rme3B/XAcGucSsipyxoVJlHWyaT5HoqDUSMgDvj9FER76AJUoCJ0uXRCwE2iTsZXko/Y EnXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691996802; x=1692601602; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U0QTEI38kWU+1C4vkrjNkWzQdHCYPiEyuFiG5Wveegg=; b=ULvMHVPc7kQQuO7IfrXzuE40KzBBENkR6Thfg8Hcf5ivGPeqVIgXUGtqA9IGEcspzT u770y/dM9m2ncccDJRO0BOBSFDMU25a6MQthZF3yulvWBzoiUvvhtN+jQ/hvQ1u7SuLt +dpYz0sNTOjgOKEdMz5jGcJpHG/JIJ7MYsw+dSrhvmNqqD+IO5x4F8qQXqbzFKuDsbn6 eVp6zPGdygaoJUjCkdcbs7Z0YhU9/WnAqLVtv6mXOHwqkVtd718BKI4cWh/QeYEjvvCv FLjsWzBh8CnwM116fsNAaTw36kFwec/38Q1j8ukHfOSca0/deJKSvneiONGbhyPlPAS6 LxSA== X-Gm-Message-State: AOJu0YyQbg4s6dynE4tkFvmUqdKr7NeGri5a+v6a9ceu5VnjfVIaYDhv hA1K519mGdUkMyDYDf2JFCg/Q17o6s9EQX8ueaw= X-Google-Smtp-Source: AGHT+IFy+oNpAUNOC4uqdO/JwamFBcN+5BR1gR2A+deH4xyJvLCUA/81trtduPFONVknJr9I8+UfL9yCEBCtIA20XMM= X-Received: by 2002:a05:6871:554:b0:1bf:77d4:1c7 with SMTP id t20-20020a056871055400b001bf77d401c7mr8988041oal.13.1691996801779; Mon, 14 Aug 2023 00:06:41 -0700 (PDT) MIME-Version: 1.0 References: <3507485.1691090027@sss.pgh.pa.us> In-Reply-To: <3507485.1691090027@sss.pgh.pa.us> From: Andy Fan Date: Mon, 14 Aug 2023 15:06:30 +0800 Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Tom Lane Cc: Pavel Stehule , jian he , pgsql-hackers Content-Type: multipart/alternative; boundary="00000000000054ca230602dcb4b0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000054ca230602dcb4b0 Content-Type: text/plain; charset="UTF-8" > > > We'd still have functions like jsonb_field_as_numeric() under the > hood, but there's not an expectation that users call them explicitly. > To avoid the lots of functions like jsonb_field_as_int2/int4, I defined Datum jsonb_object_field_type(.., Oid target_oid) at last, so the function must return "internal" or "anyelement". Then we can see: select jsonb_object_field_type(tb.a, 'a'::text, 1700) from tb; ERROR: cannot display a value of type anyelement. The reason is clear to me, but I'm not sure how to fix that or deserves a fix? Or shall I define jsonb_object_field_int2/int8 to avoid this? This is an unresolved issue at the latest patch. -- Best Regards Andy Fan --00000000000054ca230602dcb4b0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

We'd still have functions like jsonb_field_as_numeric() under the
hood, but there's not an expectation that users call them explicitly.

To avoid the lots of functions like json= b_field_as_int2/int4, I defined
Datum jsonb_object_field_type(..,= Oid target_oid) at last,=C2=A0 so the
function must return "= ;internal" or "anyelement".=C2=A0 Then we can see:

select jsonb_object_field_type(tb.a, 'a'::text, 1700) fr= om tb;
ERROR: =C2=A0cannot display a value of type anyelement.

The reason is c= lear to me, but=C2=A0 I'm not sure how to fix=C2=A0that or deserves
a fix? Or shall I define jsonb_object_field_in= t2/int8 to avoid this?=C2=A0

This is an unresolved issue at the latest patch.=C2=A0
--
Best Regards
Andy Fan
--00000000000054ca230602dcb4b0--