Re: value returned by EXTRACT, date_part

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: value returned by EXTRACT, date_part
Дата
Msg-id 3517945.1598665173@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: value returned by EXTRACT, date_part  (John Lumby <johnlumby@hotmail.com>)
Ответы Re: value returned by EXTRACT, date_part  (John Lumby <johnlumby@hotmail.com>)
Список 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 по дате отправления:

Предыдущее
От: John Lumby
Дата:
Сообщение: Re: value returned by EXTRACT, date_part
Следующее
От: John Lumby
Дата:
Сообщение: Re: value returned by EXTRACT, date_part