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 1eo4G9-00078B-VT for pgsql-interfaces@arkaria.postgresql.org; Tue, 20 Feb 2018 09:30:50 +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 1eo4G8-0008Vn-RP for pgsql-interfaces@arkaria.postgresql.org; Tue, 20 Feb 2018 09:30:48 +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 1eo4G8-0008Ve-IU for pgsql-interfaces@lists.postgresql.org; Tue, 20 Feb 2018 09:30:48 +0000 Received: from mail231.strasbourg.4js.com ([92.103.31.231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eo4Fz-0008DO-E2 for pgsql-interfaces@lists.postgresql.org; Tue, 20 Feb 2018 09:30:45 +0000 Received: from [10.0.40.29] (orion.strasbourg.4js.com [10.0.40.29]) (authenticated bits=0) by mail231.strasbourg.4js.com (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id w1K9UWCm010098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for ; Tue, 20 Feb 2018 10:30:32 +0100 Subject: Re: Type scale returned by PQfmod() 65531 for time/timestamp output parameter? To: pgsql-interfaces@lists.postgresql.org 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> <7047.1519056383@sss.pgh.pa.us> From: Sebastien FLAESCH Organization: Four Js Development Tools Message-ID: <2ae51da1-f2b4-a8be-4c4d-c8b96f1f7718@4js.com> Date: Tue, 20 Feb 2018 10:30:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <7047.1519056383@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.99.3 at mail231 X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail231.strasbourg.4js.com [10.10.0.1]); Tue, 20 Feb 2018 10:30:32 +0100 (CET) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/19/2018 05:06 PM, Tom Lane wrote: > 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 > Thank you Tom. From our tests it seems to be ok to extract the time/timestamp scale... This really needs clarification, I would appreciate that the community gives more information about PQfmod()... We implement a proprietary database interface lib based on libpq, which needs to provide columnn type information (similar to ODBC's SQLDescriceCol[W]()) Type information is also used to properly do data type conversions (for ex to fetch a time(n) into a varchar(50) variable in our language), It is mission critical for us. => I will have a look at psqlODBC ... Seb