衝突(散裝UPSERT)我寫一個數據挖掘程序,它的批量插入用戶數據。批量插入,更新,如果對Postgres的
當前的SQL只是一個簡單的批量插入:
insert into USERS(
id, username, profile_picture)
select unnest(array['12345']),
unnest(array['Peter']),
unnest(array['someURL']),
on conflict (id) do nothing;
如何,如果在衝突做一個更新?我試過了:
...
unnest(array['Peter']) as a,
unnest(array['someURL']) as b,
on conflict (id) do
update set
username = a,
profile_picture = b;
但是它會拋出There is a column named "a" in table "*SELECT*", but it cannot be referenced from this part of the query.
錯誤。
編輯:
的USERS
表很簡單:
create table USERS (
id text not null primary key,
username text,
profile_picture text
);
哪個是主鍵?什麼是表格創建代碼? @user我添加的代碼 –
,這只是一個很簡單的表 –