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 1snim8-005c8J-Pl for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 18:06:09 +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 1snim3-00GSoo-9F for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2024 18:06:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1snim2-00GSog-HQ for pgsql-hackers@lists.postgresql.org; Mon, 09 Sep 2024 18:06:02 +0000 Received: from 008.lax.mailroute.net ([199.89.1.11]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1snily-000LM7-1B for pgsql-hackers@postgresql.org; Mon, 09 Sep 2024 18:06:01 +0000 Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4X2ZWm2cXCz6ClY8r; Mon, 9 Sep 2024 18:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :mime-version:user-agent:date:date:message-id:from:from :references:subject:subject:received:received; s=mr01; t= 1725905153; x=1728497154; bh=uzdjJVdDMY/qveZcVpnuLpCZV7PSYOsUjIk WnCunQyI=; b=kPspbK8NibKIVKHIcfDfGHTglTN4/Aiqroq8YxxVxAnxB1GD4WW OpSLuPnjQH5GK61lRfQ9pVi6OTZIGPt+dGWDusfPJSnOSfiBI7BkwoOtyajhyY+m YKVY/H0ibKEI1hMV94D/YeXuX/+Fy+cCrK8ewChrsSkNiZxBEEj2AsXcYORu1jWO F24gYq5YTuQQ1kN1HCOoe/HIf+u/c3ckiUBoK1/LWclQTmnn25bEHUBpaBK7/1VN 4VpH0HtBefamy0VGSXHSm+nCrq+SuLRKVWjgD5guntNRTmibk5QbvybPlhjOQOGO atNetQLXIFAhpgTWr2xiwwB1dF6BkhP8OpQ== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 6qtxA1IB-Ol4; Mon, 9 Sep 2024 18:05:53 +0000 (UTC) Received: from [73.103.120.3] (c-73-103-120-3.hsd1.in.comcast.net [73.103.120.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jcflack@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4X2ZWh50W0z6ClY8p; Mon, 9 Sep 2024 18:05:52 +0000 (UTC) Subject: Re: access numeric data in module To: Robert Haas , Tom Lane References: <3142462.1725891243@sss.pgh.pa.us> Cc: Ed Behn , pgsql-hackers@postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <66DF38F5.6050803@acm.org> Date: Mon, 9 Sep 2024 14:05:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 09/09/24 13:00, Robert Haas wrote: > I don't agree with this reponse at all. It seems entirely reasonable > for third-party code to want to have a way to construct and interpret > numeric datums. Keeping the details private would MAYBE make sense if > the internal details were changing release to release, but that's > clearly not the case. Even if it were, an extension author is > completely entitled to say "hey, I'd rather have access to an unstable > API and update my code for new releases" and we should accommodate > that. If we don't, people don't give up on writing the code that they > want to write -- they just cut-and-paste private declarations/code > into their own source tree, which is WAY worse than if we just put the > stuff in a .h file. Amen. https://tada.github.io/pljava/preview1.7/pljava-api/apidocs/org.postgresql.pljava/org/postgresql/pljava/adt/Numeric.html The above API documentation was written when the PostgreSQL source comments read "values of NBASE other than 10000 are considered of historical interest only and are no longer supported in any sense". I will have to generalize it a bit more if other NBASEs are now to be considered again. If Tom prefers the idea of keeping the datum layout strongly encapsulated (pretty much uniquely among PG data types) and providing only a callable C API for manipulating it, then I might propose something like the above- linked Java API as one source of API ideas. I think it's worth remembering that most PLs will have their own libraries (sometimes multiple alternatives) for arbitrary-precision numbers, and it's hard to generalize about /those/ libraries regarding what API they will provide for most efficiently and faithfully converting a foreign representation to or from their own. Conversion through a decimal string (a) may not be most efficient, and (b) may not faithfully roundtrip possible combinations of digits, displayScale, and weight. From Java's perspective, there has historically been a significant JNI overhead for calling from Java into a C API, so that it's advantageous to know the memory layout and keep the processing in Java. There is at last a batteries-included Java foreign-function interface that can make it less costly to call into a C API, but that has only landed in Java 22, which not everyone will be using right away. Regards, -Chap