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 1qVYB0-000WyS-Df for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Aug 2023 14:04:10 +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 1qVYAx-004lnx-NI for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Aug 2023 14:04:07 +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 1qVYAx-004lnp-D8 for pgsql-hackers@lists.postgresql.org; Mon, 14 Aug 2023 14:04:07 +0000 Received: from anastigmatix.net ([68.171.216.17]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVYAv-0005ei-6o for pgsql-hackers@postgresql.org; Mon, 14 Aug 2023 14:04:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zsTfj5V3L5dlvOLKXqIHIPCKBpsbHcJaRaBugmEIobE=; b=CIQelms+hiGGaxf/b14m54as/I VDkxYIa/hG3sxPumt11VYLlOw/iwqulkCBn7OW2P22jytcAI51zneh5aKWujC0Dr5eKckRMHYa6YG 8sndv0prZ23B05kjrcjLV9TfhrjWXgVZAyqnb9KwHPwvK7IQjCjqfWWvqS9n/GYkdV2NIhBYwXddQ i3ek/yr7jA3L7U+/ADjC8wdFG1AUbsfqbmvvyMf4hN/S0fvbj1Z4cRCCTGjhFRHuIHEx59lmBq4RX 7TXW4B70tIvc63EK5D3zIArJGXIqHCodXqDmbA/4lqc9995RUaPLvJ3gXWThwynmsFXg2tajCPsD0 otNuiUog==; Received: from [::1] (port=37570 helo=adam.ace-host.net) by adam.ace-host.net with esmtpa (Exim 4.96) (envelope-from ) id 1qVYAr-003tFu-0V; Mon, 14 Aug 2023 10:04:03 -0400 MIME-Version: 1.0 Date: Mon, 14 Aug 2023 10:04:03 -0400 From: Chapman Flack To: Andy Fan Cc: Tom Lane , Pavel Stehule , jian he , pgsql-hackers Subject: Re: Extract numeric filed in JSONB more effectively In-Reply-To: References: <3507485.1691090027@sss.pgh.pa.us> User-Agent: Roundcube Webmail/1.6.0 Message-ID: <900892914fdc3f477b101d699efb40e0@anastigmatix.net> X-Sender: chap@anastigmatix.net Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - adam.ace-host.net X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: adam.ace-host.net: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: adam.ace-host.net: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-08-14 03:06, Andy Fan wrote: >> 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". > ... > I'm not sure how to fix that or deserves > a fix? Or shall I define jsonb_object_field_int2/int8 to avoid this? As far as I'm concerned, if the intent is for this to be a function that is swapped in by SupportRequestSimplify and not necessarily to be called by users directly, I don't mind if users can't call it directly. As long as there is a nice familiar jsonb function the user can call in a nice familiar way and knows it will be handled efficiently behind the curtain, that seems to be good enough for the user--better, even, than having a new oddball function to remember. However, I believe the rule is that a function declared to return internal must also declare at least one parameter as internal. That way, a user won't be shown errors about displaying its returned value, because the user won't be able to call it in the first place, having no values of type 'internal' lying around to pass to it. It could simply have that trailing oid parameter declared as internal, and there you have a strictly internal-use function. Providing a function with return type declared internal but with no parameter of that type is not good, because then a user could, in principle, call it and obtain a value of 'internal' type, and so get around the typing rules that prevent calling other internal functions. Regards, -Chap