1

I'm running psycopg2 on Python 3.9, querying a Redshift table.

I'm querying a table with a SELECT * passed to the cursor.execute() method:

query = 'select * from my_schema.my_table;'
cursor = connection.cursor(cursor_factory=RealDictCursor) # psycopg2 connection
cursor.execute(query)
data = cursor.fetchall()

And, I'm getting back the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mypython.py", <lines>
  File "/usr/local/lib/python3.9/site-packages/psycopg2/extras.py", line 236, in execute
    return super().execute(query, vars)
psycopg2.errors.InternalError_: Assert
DETAIL:
  -----------------------------------------------
  error:  Assert
  code:      1000
  context:   status == 0 - timestamp: '-9223372036854775808'
  query:     <query #>
  location:  cg_util.cpp:705
  process:   <process>
  -----------------------------------------------

I can query other tables in different schema and the same schema, but not this table.

The table has varchar and timestamp column types. I'm using the -infinity Special Date/Time Input in one of the columns.

Brass
  • 56
  • 4

1 Answers1

0

The issue is the -infinity timestamp value, psycopg2 doesn't seem to be agreeable to it.

In this case, I'm able to use a different built-in value, since my actual reason for using -infinity is to have a value that means "long ago".

update my_schema.my_table
set ts_column = timestamp 'epoch'
where my_table.ts_column = timestamp '-infinity';
Brass
  • 56
  • 4
  • 1
    No, the issue is Python does not support `+-infinity`. If you want a solution see here [Date adaptation](https://www.psycopg.org/docs/usage.html#adapt-date) and look for section 'Infinite dates handling'. – Adrian Klaver Dec 21 '21 at 23:18