snippetsqlMinor
Function extract() from date returns double precision value
Viewed 0 times
precisionfunctiondatevaluedoublereturnsextractfrom
Problem
Why does the Postgres function
Only reason I could imagine is, there are some locales using calendars (those not Gregorian calendars and supported by Postgres), calculate date/time differently and possible return float number.
extract() return double precision from date value?Only reason I could imagine is, there are some locales using calendars (those not Gregorian calendars and supported by Postgres), calculate date/time differently and possible return float number.
Solution
Because the return values can be large or a decimal number.
Double precision will accept a wide range of values
Looking at other numeric types, you only have decimal which will have overhead: you don't know the return scale or precision needed beforehand so it would have to wide
See PG docs
Double precision will accept a wide range of values
Looking at other numeric types, you only have decimal which will have overhead: you don't know the return scale or precision needed beforehand so it would have to wide
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
Result: 982384720.12See PG docs
Code Snippets
SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
Result: 28.5
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40.12-08');
Result: 982384720.12Context
StackExchange Database Administrators Q#84305, answer score: 5
Revisions (0)
No revisions yet.