【问题标题】:obtaining a rowcount when running python cursor.execute on Redshift for UNLOAD command在 Redshift 上运行 python cursor.execute for UNLOAD 命令时获取行数
【发布时间】:2019-11-21 22:47:18
【问题描述】:

标题确实说明了一切。当我通过游标调用卸载时,它工作得很好。但是,当我尝试获取已卸载数量的记录计数时,它返回-1。这对应于我认为的文档(http://initd.org/psycopg/docs/cursor.html,“-1...最后一次操作的行数,如果它不能由接口确定”)

connection = psycopg2.connect(conn_string)
ext_cur = connection.cursor()
ext_cur.execute("unload ('Select * from test;') to 's3://test/test_output_191121215843.txt' credentials 'aws_access_key_id=xxxxx;aws_secret_access_key=xxxxx' delimiter as '|' PARALLEL OFF  HEADER ALLOWOVERWRITE;")
Print(str(ext_cur.rowcount()))

但我想知道是否有人找到了解决方法? (缺少从 S3 下载文件并运行行数!)。 当我从 DBVisualizer 等桌面数据库工具运行相同的卸载命令时,它会显示卸载的行数。所以我必须相信有办法从数据库中获取它..

来自 DBVisulizer 日志窗口的示例响应:

17:44:03  [UNLOAD - 0 rows, 0.955 secs]  Command processed. No rows were affected
SQL State: 01000 --- UNLOAD completed, 471 record(s) unloaded successfully.
... 1 statement(s) executed, 0 rows affected, exec/fetch time: 0.955/0.000 sec  [1 successful, 1 SQL warnings, 0 errors]

【问题讨论】:

    标签: python amazon-s3 amazon-redshift


    【解决方案1】:

    找到了..运行卸载后,调用:

    select pg_last_unload_count();
    

    (https://docs.aws.amazon.com/redshift/latest/dg/PG_LAST_UNLOAD_COUNT.html)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 2011-05-21
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      相关资源
      最近更新 更多