'ERROR: date/time field value out of range: "1658792421"
I'm trying to convert and epoch to a string on PostgreSQL and I get the following error:
ERROR: date/time field value out of range: "1658792421"
The query is the following:
SELECT to_timestamp('1658792421', 'DD-MM-YYYY');
Not really sure why this happens.
I'm using PostgreSQL 13.
Thanks
Solution 1:[1]
You need to pass a number, not a string if you want to convert the dreaded Unix epoch. But that version of to_timestamp doesn't accept a format mask (as you are passing a number).
SELECT to_timestamp(1658792421)
If you want to format that timestamp value, use to_char()
SELECT to_char(to_timestamp(1658792421), 'DD-MM-YYYY')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | a_horse_with_no_name |
