【问题标题】:Python copy_from not working and not throwing errorsPython copy_from 不工作且不抛出错误
【发布时间】:2013-05-31 17:33:58
【问题描述】:

我有以下过程未按预期将数据加载到表中:

def upload_data(parsed_buffer):  

    parsed_buffer.seek(0)

    try:

        con = psycopg2.connect(database=database, user=user, password=pw, host=host) 
        cur = con.cursor()
        try:
            cur.copy_from(parsed_buffer, 'staging.vcf_ht')
        except StandardError, err:
            conn.rollback()
            print("   Caught error (as expected):\n", err)

    except psycopg2.NotSupportedError as e:
        now = time.strftime("%H:%M:%S +0000", time.localtime())
        print("Copy failed at: " + now + " - " + e.pgerror)
        sys.exit(1)

    finally:

            if con:
                con.close()
                now = time.strftime("%H:%M:%S +0000", time.localtime())
                print('Finished loading data at:' + now)

在其他帖子中,他们讨论了在写入后添加搜索功能。那是在我的代码的第 3 行。这没有用。我检查了其他几件事。 1. 字符串缓冲区填充有制表符分隔的数据。 2. 如果我将输出重定向到一个文件并在 psql 中使用 \copy 命令,它会像宣传的那样工作。 3. 如果我写一个插入语句而不是字符串缓冲区,这也可以(但这对性能不利)。此过程终止并抛出任何错误。

【问题讨论】:

  • 问题是没有提交语句。补充:con.commit()

标签: python postgresql-9.2


【解决方案1】:

问题是没有提交语句。补充:con.commit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多