I want to do
" on conflict (time) do update set name , description "
but I have no idea when I use stdin with csv , I don't know what name equal what? and description equal what...
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()
https://www.postgresql.org/docs/current/static/sql-copy.html
there is no
copy ... on conflict do
statement in postgreshttps://www.postgresql.org/docs/current/static/sql-insert.html
only
insert ... on conflict do
Thanks for every master's solution.
this is my solution.
In this SO post, there are two answers that -combined together- provide a nice solution for successfully using
ON CONFLICT
. The example below, usesON CONFLICT DO NOTHING;
: