Re: value returned by EXTRACT, date_part - Mailing list pgsql-sql

From Tom Lane
Subject Re: value returned by EXTRACT, date_part
Date
Msg-id 3517945.1598665173@sss.pgh.pa.us
Whole thread Raw
In response to Re: value returned by EXTRACT, date_part  (John Lumby <johnlumby@hotmail.com>)
Responses Re: value returned by EXTRACT, date_part  (John Lumby <johnlumby@hotmail.com>)
List pgsql-sql
John Lumby <johnlumby@hotmail.com> <DM6PR06MB5562A231945B39D33623849BA3520@DM6PR06MB5562.namprd06.prod.outlook.com>
writes:
> But also (and probably not easily changed now) it would make EXTRACT
> more generally useful if it included a fractional part for every field
> type where meaningful.

> Is there any reason why it should not?

The SQL spec says otherwise.

Section 4.6.2 "Datetimes" in SQL:2011 defines timestamps as containing
the six fields year, month, day, hour, minute, second (dates contain
only the first three, times only the second three, but otherwise are
similar), plus possibly timezone_hour and timezone_minute.  All of
these except the seconds field are specified to be integers.
Furthermore, the EXTRACT function is specifically defined to return
one of these fields.

4.6.3 "Intervals" lays down basically the same sorts of rules for
intervals: they are made of component fields and only the seconds
field can have a fractional part.

PG does offer a nonstandard EPOCH "field" in EXTRACT, which tries
to convert the timestamp or interval as a whole to some number of
seconds.  Possibly you could make use of that, perhaps after first
applying date_trunc, to get what you're after.  The whole enterprise
is pretty shaky though; for example you cannot convert months to days
or vice versa without making fundamentally-indefensible assumptions.

            regards, tom lane



pgsql-sql by date:

Previous
From: John Lumby
Date:
Subject: Re: value returned by EXTRACT, date_part
Next
From: John Lumby
Date:
Subject: Re: value returned by EXTRACT, date_part