【发布时间】:2018-01-08 02:39:57
【问题描述】:
我正在做一个 upsert。
owner.sq_properties = ['name', 'place', 'email_address', 'preferred_transport', 'note', 'address_line_one', 'address_line_two', 'address_line_three', 'contact_one', 'contact_two', 'contact_three', 'gst_number', 'nickname']
声明:
sq = sql.SQL("insert into master.customer select * from public.customer on conflict (id) do update set({})=({})").format(sql.SQL(',').join(sql.Identifier(n) for n in owner.sq_properties),sql.SQL(',').join(sql.Identifier("excluded."+n) for n in owner.sq_properties))
当我执行时:
print(sq.as_string(cursor))
输出是:
insert into master.customer select * from public.customer on conflict (id) do update set ("name", "place", "email_address", "preferred_transport", "note", "address_line_one", "address_line_two", "address_line_three", "contact_one", "contact_two", "contact_three", "gst_number", "nickname") = ("excluded.name", "excluded.place", "excluded.email_address", "excluded.preferred_transport", "excluded.note", "excluded.address_line_one", "excluded.address_line_two", "excluded.address_line_three", "excluded.contact_one", "excluded.contact_two", "excluded.contact_three", "excluded.gst_number", "excluded.nickname")
错误:
cursor.execute(sq)
psycopg2.ProgrammingError: column "excluded.name" does not exist
LINE 1: ...o", "contact_three", "gst_number", "nickname") = ("excluded..
我做错了什么?
【问题讨论】: