【发布时间】:2017-09-15 15:44:05
【问题描述】:
我正在尝试将行批量插入到 postgres 数据库中,并在冲突时更新冲突的行。我想知道最好的方法是什么。我目前的查询无法插入任何行,但如果我删除 on 冲突,它会完美运行。我也没有收到任何错误。
这是我正在使用的当前查询:
'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)
提前致谢。如果您需要更多信息,请告诉我。
【问题讨论】:
-
不太明白这与批处理文件有什么关系?在您的问题中没有看到任何批处理文件代码。
标签: sql postgresql