Postgresql Batch insert and on conflict batch update
我正在尝试批量插入postgres数据库并在冲突时更新冲突的行。 我想知道最好的办法是什么。 查询我目前无法插入任何行,但如果我删除了冲突,它的工作完美。 我也没有从我能说的任何错误中得到任何错误。
这是我正在使用的当前查询:
'INSERT INTO table (x1, x2, x3, ...) VALUES %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,... ON CONFLICT DO UPDATE SET (x4, x5, x6) = %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,...'
我有一个函数,用形式(x1,x2,...)的元组填充%s值
我的桌子看起来像这样
Table"public.table"
    Column    |  Type   |                           Modifiers
--------------+---------+-----------------------------------------------
 id           | integer | not null default nextval('table_id_seq'::regclass)
 x1           | text    | not null
 x2           | text    | not null
 x3           | integer | not null
 x4           | text    | not null
 x5           | text    | not null
 x6           | text    | not null
Indexes:
   "table_feature_pkey" PRIMARY KEY, btree (id)
提前致谢。 如果您需要其他信息,请告诉我。
您将使用明显不正确的语法。 有桌子
| 1 | CREATE TABLE a_table(id serial PRIMARY KEY, x1 INT, x2 INT); | 
在psql中尝试这个
| 1 2 3 4 | INSERT INTO a_table (x1, x2)  VALUES (1,2), (3,4) ON conflict do UPDATE SET (x1, x2) = (1,2), (3,4); | 
要得到
| 1 2 | ERROR:  syntax error at OR near"3" LINE 4: UPDATE SET (x1, x2) = (1,2), (3,4); | 
另一方面,在这种情况下,
检查
1.插入之前
 
2.command
 
3.插入后
