【发布时间】:2018-06-09 16:54:11
【问题描述】:
我想做
" on conflict (time) do update set name , description "
但我不知道什么时候将 stdin 与 csv 一起使用,我不知道什么名称等于什么?和描述等于什么......
table_a:
xxx.csv:
with open('xxx/xxx.csv', 'r', encoding='utf8') as f:
sql = """
COPY table_a FROM STDIN With CSV on conflict (time)
do update set name=??, description=??;
"""
cur.copy_expert(sql, f)
conn.commit()
【问题讨论】:
-
创建一个临时表,将您的 csv 复制到那里,然后从所述临时表插入到您的主表中并解决所需的冲突。
标签: python postgresql csv stdin psycopg2