【发布时间】:2019-12-19 16:34:07
【问题描述】:
我有一个在 Python 中运行的 Postgres(redshift) 查询,它输出一个字段及其值。我想运行另一个使用该查询中的值的查询。但是,当我运行以下代码时,它给了我一个错误:
taskinstance.py:1051} ERROR - no results to fetch
这是我的代码:
def get_etl_recordd():
pg_hook = PostgresHook(postgre_conn_id="postgres_default", schema='db1')
connection = pg_hook.get_conn()
nt_cur = connection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
atest_update_query = "select max(updated_at) from schema1.table1 group by updated_at order by updated_at asc limit 1;"
nt_cur.execute(atest_update_query)
result = nt_cur.fetchone()
max_updated_at = result.max
cursor2= connection.cursor()
latest_update_query1 = "select * from schema1.table1 where updated_at <= '{}'; commit;".format(max_updated_at)
cursor2.execute(latest_update_query1)
d=cursor2.fetchone()
connection.close()
知道为什么会这样吗? atest_updated_query 的值是一个时间戳,latest_updated_query1 实际上有一个输出。任何帮助将不胜感激。
这是我在 Python/Airflow 中运行的 Postgres(Redshift) 查询。
【问题讨论】:
-
请清理错别字(例如,
atest_updated_query,latest_upadted_query1,get_etl_recordd()`)
标签: python postgresql amazon-redshift airflow mysql-python