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 1ep4vl-0006eT-93 for pgsql-general@arkaria.postgresql.org; Fri, 23 Feb 2018 04:25:57 +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 1ep4vj-0007E0-Kc for pgsql-general@arkaria.postgresql.org; Fri, 23 Feb 2018 04:25:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ep4vj-0007Dr-9u for pgsql-general@lists.postgresql.org; Fri, 23 Feb 2018 04:25:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ep4vc-0006QZ-M4 for pgsql-general@lists.postgresql.org; Fri, 23 Feb 2018 04:25:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w1N4Pdf3016883; Thu, 22 Feb 2018 23:25:39 -0500 From: Tom Lane To: Michael Paquier cc: Demitri Muna , pgsql-general@lists.postgresql.org Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"? In-reply-to: <20180223023138.GB15131@paquier.xyz> References: <21871.1519185281@sss.pgh.pa.us> <19E43B98-06A3-4D78-9F86-B69D12D4BAFD@demitri.com> <20180223023138.GB15131@paquier.xyz> Comments: In-reply-to Michael Paquier message dated "Fri, 23 Feb 2018 11:31:38 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16881.1519359939.1@sss.pgh.pa.us> Date: Thu, 22 Feb 2018 23:25:39 -0500 Message-ID: <16882.1519359939@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > On Thu, Feb 22, 2018 at 08:00:45PM -0500, Demitri Muna wrote: >> Out of curiosity, how does one read a numeric type from within a C >> extension (i.e. get a number value out of the Datum type)? > PG_GETARG_NUMERIC(), no? I think the core point here is that PG's "numeric" type *isn't* any primitive C type; it's a variable-length BCD encoding. If you want to deal with it you can, but you must spend some time reading src/backend/utils/adt/numeric.c, as Michael suggests. If you just want a convenient C approximation, then work with float8 and let the implicit-coercion machinery do the conversion for you. regards, tom lane