【问题标题】:Why is my psycopg2 query failing with `psycopg2.errors.InternalError_: Assert`?为什么我的 psycopg2 查询因 `psycopg2.errors.InternalError_: Assert` 而失败?
【发布时间】:2022-01-23 05:14:24
【问题描述】:

我在 Python 3.9 上运行 psycopg2,查询 Redshift 表。

我正在查询一个带有 SELECT * 传递给 cursor.execute() 方法的表:

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

而且,我得到了以下信息:

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>
  -----------------------------------------------

我可以查询不同架构和相同架构的其他表,但不能查询这个表。

该表具有varchartimestamp 列类型。我在其中一列中使用了-infinity Special Date/Time Input

【问题讨论】:

  • 如果删除“cursor_factory=RealDictCursor”会发生什么?

标签: python postgresql psycopg2


【解决方案1】:

问题在于-infinity 时间戳值,psycopg2 似乎不同意它。

在这种情况下,我可以使用不同的内置值,因为我使用 -infinity 的实际原因是有一个表示“很久以前”的值。

update my_schema.my_table
set ts_column = timestamp 'epoch'
where my_table.ts_column = timestamp '-infinity';

【讨论】:

  • 不,问题是 Python 不支持 +-infinity。如果您需要解决方案,请参阅此处Date adaptation 并查找“无限日期处理”部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2012-04-06
  • 2011-04-24
相关资源
最近更新 更多