【发布时间】:2022-01-01 14:00:02
【问题描述】:
我有这样的代码,
cursor_local.execute("""SELECT "Name", "Level_Capacity", "Source_NE", "Sink_NE" FROM "table1" WHERE "Name" LIKE '%WDM%' """)
rows = cursor_local.fetchall()
psycopg2.extras.execute_batch(cursor_local, 'INSERT INTO table2("Name", "Level_Capacity", "Source_NE", "Sink_NE") VALUES (%s, %s, %s, %s)', (*rows,) )
connection_local.commit()
我只想从 table1 (postgres db) 将新记录插入到 table2 中,只插入那些不在 table2 中的记录。 在table2中“Id”是自动生成的并且是唯一的(其他不是唯一的),插入时我想检查它是否存在“Name”、“Source_NE”、“Sink_NE”。
【问题讨论】:
标签: python sql postgresql