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 1ennxt-0001oH-TU for pgsql-interfaces@arkaria.postgresql.org; Mon, 19 Feb 2018 16:06:53 +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 1ennxs-0004nS-KC for pgsql-interfaces@arkaria.postgresql.org; Mon, 19 Feb 2018 16:06:52 +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 1ennxs-0004nJ-Eo for pgsql-interfaces@lists.postgresql.org; Mon, 19 Feb 2018 16:06:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ennxp-0001pK-WA for pgsql-interfaces@lists.postgresql.org; Mon, 19 Feb 2018 16:06:51 +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 w1JG6NLG007048; Mon, 19 Feb 2018 11:06:23 -0500 From: Tom Lane To: Sebastien FLAESCH cc: pgsql-interfaces@lists.postgresql.org Subject: Re: Type scale returned by PQfmod() 65531 for time/timestamp output parameter? In-reply-to: <91fabdcd-0eb3-c970-a28c-248a6ff8a360@4js.com> References: <093e1214-7057-f80c-5c3c-74076b7bb555@4js.com> <7537.1518711940@sss.pgh.pa.us> <13939.1518794152@sss.pgh.pa.us> <91fabdcd-0eb3-c970-a28c-248a6ff8a360@4js.com> Comments: In-reply-to Sebastien FLAESCH message dated "Mon, 19 Feb 2018 12:16:45 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7046.1519056383.1@sss.pgh.pa.us> Date: Mon, 19 Feb 2018 11:06:23 -0500 Message-ID: <7047.1519056383@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Sebastien FLAESCH writes: > On 02/16/2018 04:15 PM, Tom Lane wrote: >> You could try running it through the typmodout function for the column's >> datatype. I don't offhand know of any built-in types for which that would >> be a really plausible typmod, though. Are you sure your client code isn't >> mistakenly narrowing it to int16 somewhere? > As I wrote in my initial mail, I do the following: > #define VARHDRSZ 4 > int pgfmod = PQfmod(st->pgResult, i); > int pgprec = (pgfmod >> 16); > int pgscal = ((pgfmod - VARHDRSZ) & 0xffff); > int pgleng = (pgfmod - VARHDRSZ); That might --- I don't recall offhand --- be the right decoding for the typmod of a column of type NUMERIC. It's certainly not right for any other datatype. Also, you don't seem to be accounting for the fact that negative typmod always means "no typmod specified". regards, tom lane