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 1enjRE-0002Ar-0D for pgsql-interfaces@arkaria.postgresql.org; Mon, 19 Feb 2018 11:16:52 +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 1enjRC-0006EA-N7 for pgsql-interfaces@arkaria.postgresql.org; Mon, 19 Feb 2018 11:16:50 +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 1enjRC-0006E1-Ho for pgsql-interfaces@lists.postgresql.org; Mon, 19 Feb 2018 11:16:50 +0000 Received: from mail231.strasbourg.4js.com ([92.103.31.231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1enjR9-000422-M1 for pgsql-interfaces@lists.postgresql.org; Mon, 19 Feb 2018 11:16:49 +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 w1JBGjnn029807 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for ; Mon, 19 Feb 2018 12:16:45 +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> From: Sebastien FLAESCH Organization: Four Js Development Tools Message-ID: <91fabdcd-0eb3-c970-a28c-248a6ff8a360@4js.com> Date: Mon, 19 Feb 2018 12:16:45 +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: <13939.1518794152@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]); Mon, 19 Feb 2018 12:16:45 +0100 (CET) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/16/2018 04:15 PM, Tom Lane wrote: > Sebastien FLAESCH writes: >> Would be nice however to have some clear documentation about PQfmod() interpretation... >> What means exactly 65531/0xFFFB? > > 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? > > regards, tom lane > > 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); As no clear documentation is available for PQfmod() interpretation I looked at the internal header files and ECPG sources. The VARHDRSZ is sizeof(int32), but it's not available in standard PostgreSQL PQ header files. It can be found in include/postgresql/server/c.h: #define VARHDRSZ ((int32) sizeof(int32)) In the ECPG sources you can see: src/interfaces/ecpg/ecpglib/descriptor.c: case ECPGd_scale: if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff)) { va_end(args); return (false); } ecpg_log("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff); break; case ECPGd_precision: if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16)) { va_end(args); return (false); } ecpg_log("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16); break; Seb