Tôi đang viết chương trình khai phá dữ liệu, số lượng lớn chèn dữ liệu người dùng.Chèn số lượng lớn, cập nhật nếu xung đột (upsert số lượng lớn) trên Postgres
SQL hiện tại chỉ là một số lượng lớn chèn đơn giản:
insert into USERS(
id, username, profile_picture)
select unnest(array['12345']),
unnest(array['Peter']),
unnest(array['someURL']),
on conflict (id) do nothing;
Làm thế nào để làm một bản cập nhật nếu trên cuộc xung đột? Tôi đã thử:
...
unnest(array['Peter']) as a,
unnest(array['someURL']) as b,
on conflict (id) do
update set
username = a,
profile_picture = b;
Nhưng nó ném lỗi There is a column named "a" in table "*SELECT*", but it cannot be referenced from this part of the query.
.
EDIT:
Mục USERS
rất đơn giản:
create table USERS (
id text not null primary key,
username text,
profile_picture text
);
Khóa chính nào? Mã tạo bảng là gì? –
@user Tôi đã thêm mã, nó chỉ là một bảng rất đơn giản –