如何将PostgreSQL中的二进制blob保存到文件中?

时间:2016-05-25 11:57:12

标签: python postgresql psycopg2

这是我的代码:

shape

{{1}}有类型blob(bytea)。我需要把它保存在FS上。我怎么能用Python做到这一点?

1 个答案:

答案 0 :(得分:0)

只需将其写入磁盘:

currSrc.execute("""
    SELECT request_id, time_beg, shape
    FROM "REQUESTS"
    WHERE fl_ready=1
""")
rs = cursor.fetchall()
f = open('/path/to/the/file', 'wb')
f.write(rs[0][2])
f.close()

[0][2]的原因是它是结果集的第一行和第三列。

相关问题