[Python] How to handle infinity timestamptz?

Discussão em 'Python' iniciado por Stack, Janeiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    Executing:

    await pg_acursor.execute("SELECT * FROM pg_roles;")
    await pg_acursor.fetchall()


    ...

    File "/usr/local/lib/python3.10/site-packages/psycopg/cursor_async.py", line 235, in fetchall
    records = self._tx.load_rows(self._pos, self.pgresult.ntuples, self._make_row)
    File "psycopg_binary/_psycopg/transform.pyx", line 463, in psycopg_binary._psycopg.Transformer.load_rows
    File "psycopg_binary/types/datetime.pyx", line 796, in psycopg_binary._psycopg.TimestamptzLoader.cload
    psycopg.DataError: timestamp too large (after year 10K): 'infinity'


    Mysteriously, this doesn't fail on my local machine (using Docker's postgres:latest). But does fail on a brand new Amazon RDS postgres 16.3 instance. I assume this is the rolvaliduntil timestamptz column and, and Amazon sets the value to infinity instead of null for no good reason.

    So... any idea how to coerce postgres to handle such dates gracefully (e.g. parse as null).

    Continue reading...

Compartilhe esta Página