Search code examples
pythonjavapostgresqlpgadmin-4

How to fix postgres error; time zone displacement out of range?


CurrentTimeStamp (timestamp with time zone not null) column's Date-Time Records in BOOKS postgres db table are stored in the format:

2022-10-29 00:00:00+00

There's a java API which fetches records from this table, using the CurrentTimeStamp column, Prior to that, there's a python API which provides a timestamp in the above format to the java API, and for the time field, it internally fetches the current time:

datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S+%f')[0:22]

Querying the table, using pgAdmin:

SELECT * FROM BOOKS WHERE CurrentTimeStamp BETWEEN '2022-10-29 10:00:00+00' and '2022-10-29 11:00:00+45';

ERROR: time zone displacement out of range: "2022-10-29 00:00:00+45" SQL state: 22009

The issue is in the millisecond part of the timestamp, that is, after the plus(+) symbol. Keeping that as 00, works perfectly. It also works till the value is 15.

This is part of very busy banking microservices, which are going to be hit every hour, to fetch half a million records. So, this millisecond part is important, and cannot be hardcoded to 00.

Is there a way out?


Solution

  • The part after "+" is not milliseconds though, is it. That is how you represent the tine-zone. Which can't be an offset of 45 hours.