Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1epI0G-0000X1-Sq for pgsql-general@arkaria.postgresql.org; Fri, 23 Feb 2018 18:23:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epI0F-00046u-Cb for pgsql-general@arkaria.postgresql.org; Fri, 23 Feb 2018 18:23:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1epI0E-00046l-OC for pgsql-general@lists.postgresql.org; Fri, 23 Feb 2018 18:23:27 +0000 Received: from gorilla.birch.relay.mailchannels.net ([23.83.209.75]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1epI07-0008Gn-Tm for pgsql-general@lists.postgresql.org; Fri, 23 Feb 2018 18:23:26 +0000 X-Sender-Id: 5xi41l16bi|x-authuser|_demitri_@demitri.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C4016720732 for ; Fri, 23 Feb 2018 18:23:15 +0000 (UTC) Received: from ghost.mxroute.com (unknown [100.96.29.46]) (Authenticated sender: 5xi41l16bi) by relay.mailchannels.net (Postfix) with ESMTPA id 3DA5A7210BF for ; Fri, 23 Feb 2018 18:23:15 +0000 (UTC) X-Sender-Id: 5xi41l16bi|x-authuser|_demitri_@demitri.com Received: from ghost.mxroute.com (ghost-outgoing.mxroute.com [172.18.36.240]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.13.1); Fri, 23 Feb 2018 18:23:15 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: 5xi41l16bi|x-authuser|_demitri_@demitri.com X-MailChannels-Auth-Id: 5xi41l16bi X-Chemical-Lettuce: 2ebc8c270318647c_1519410195618_1788191677 X-MC-Loop-Signature: 1519410195618:2615870502 X-MC-Ingress-Time: 1519410195617 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=demitri.com ; s=default; h=Message-Id:In-Reply-To:To:References:Date:Subject:Mime-Version :Content-Transfer-Encoding:Content-Type:From:Sender:Reply-To:Cc: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=krbd0Gb5SGzMQfzwjTAzw3dRQrjAGPV1/9DjpJEyLQg=; b=OtMTi/CpdMqD4R1FoiFyzDOSqX ++s0U+kII0+wx6NHg+uT5/GduvtnCGQshjQKbSr34PEWC1CUP3iCQ0gvnE/sOAJ/p00G5e2OfBIxQ QhmNKGPzfVK/PVI200yLR9usmmILfk69jgIA1FxEqj8t3GL30tV4FrMt48UIgUK19w5GbAx4XsZSz BOZqvAdSQxaJG2UggZbiP4Ryra0aYvBCRI/+b0kcp5f5LLfbtPrD0h8P1Dkn7JNe0H0n2X4XYhKD6 mS59pzpHi8OgOWys1AQeDSnj1GNPRVPmKKREjiHRQLXQuUuiV/qmsO1XKBR40VfrRvRev2+OdbWkk kHyVrFHw==; From: Demitri Muna Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"? Date: Fri, 23 Feb 2018 13:23:12 -0500 References: <21871.1519185281@sss.pgh.pa.us> <19E43B98-06A3-4D78-9F86-B69D12D4BAFD@demitri.com> <20180223023138.GB15131@paquier.xyz> To: pgsql-general@lists.postgresql.org In-Reply-To: <20180223023138.GB15131@paquier.xyz> Message-Id: <66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com> X-Mailer: Apple Mail (2.3445.5.20) X-AuthUser: _demitri_@demitri.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On Feb 22, 2018, at 9:31 PM, Michael Paquier = wrote: > PG_GETARG_NUMERIC(), no? That function returns an object of datatype =E2=80=9CNumeric=E2=80=9D = which still requires some (not immediately obvious) conversation to a = double (or whatever primitive C type). > When working on implementing your own data > types or when hacking out functions which manipulate arguments of an > existing datatype, looking at the input and output functions help a > lot. In your case, numeric_in and numeric_out in > src/backend/utils/adt/numeric.c is full of hints. I spent an hour diving into the code out of curiosity. I found useful = functions like this: double numeric_to_double_no_overflow(Numeric n) They=E2=80=99re available from the PostgreSQL main source code, but not = exposed in the public headers. (Maybe I was missing something.) There = was enough there where I could see a way to copy/paste or otherwise link = to those methods, but as Tom pointed out, implicit coercion handles what = I need so I=E2=80=99ll stick with that. Cheers, Demitri