From: John Lumby <johnlumby@hotmail.com>
To: pgsql-sql@lists.postgresql.org
Subject: value returned by EXTRACT, date_part
Date: Fri, 28 Aug 2020 13:43:12 -0400
Message-ID: <DM6PR06MB5562115198C798B1C06B32DBA3520@DM6PR06MB5562.namprd06.prod.outlook.com> (raw)
I notice that although EXTRACT(field FROM source) returns a value of
type double-precision,
for some field types, it apparently rounds the value to an integer,
(even though the exact value is not integral),
whereas for others it returns the exact value including any fractional
part un-rounded. Examples can be seen in the book :
SELECT EXTRACT(DAY FROM INTERVAL '40 days 1 minute');
Result: 40
rounded down from 40.0.0006944444444444445
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16
20:38:40.12-08');
Result: 982384720.12
un-rounded
This seems inconsistent to me - and undocumented as far as I can tell.
Is there any reason for this? And can it be relied on in programs?
Cheers, John
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: johnlumby@hotmail.com
Subject: Re: value returned by EXTRACT, date_part
In-Reply-To: <DM6PR06MB5562115198C798B1C06B32DBA3520@DM6PR06MB5562.namprd06.prod.outlook.com>
References: <DM6PR06MB5562115198C798B1C06B32DBA3520@DM6PR06MB5562.namprd06.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox