如何消除 postgresql 的批量更新插入中的不明确列引用错误?
How to eliminate ambiguous column reference error in bulk upsert for postgresql?
对于以下代码,我正在尝试将批量更新插入 table。 table 称为 jobstep_to_step_relationships。如果主键列 "job_base_step_id" 已经存在于 table 中,我希望算法进行更新。
create table jobstep_to_step_relationships
(
job_base_step_id uuid default uuid_generate_v4() not null
constraint jobstep_to_step_relationships_pkey
primary key,
step_id uuid not null,
parent_job_base_step_id uuid not null,
parent_step_id uuid not null,
job_id uuid not null,
order_number integer not null,
is_group boolean not null,
created_at bigint not null,
updated_at bigint not null
);
INSERT INTO jobstep_to_step_relationships
(job_base_step_id, step_id, parent_job_base_step_id, parent_step_id, job_id, order_number,
is_group, created_at, updated_at)
VALUES (, , , , , , , , ),
(, , , , , , , , )
ON CONFLICT (job_base_step_id)
DO UPDATE SET job_base_step_id = EXCLUDED.job_base_step_id,
step_id = EXCLUDED.step_id,
parent_job_base_step_id = EXCLUDED.parent_job_base_step_id,
parent_step_id = EXCLUDED.parent_step_id,
job_id = EXCLUDED.job_id,
order_number = EXCLUDED.order_number,
is_group = EXCLUDED.is_group,
created_at = EXCLUDED.created_at,
updated_at = EXCLUDED.updated_at
WHERE EXCLUDED.job_base_step_id = job_base_step_id
AND EXCLUDED.step_id = step_id
然而,对于以下发布的代码,我收到此错误:
[2019-06-25 13:17:47] [42702] ERROR: column reference "job_base_step_id" is ambiguous
不确定我对文档的解释有误。有人可以指出什么是错的吗?
指定 table 名称以修复歧义:
WHERE EXCLUDED.job_base_step_id = jobstep_to_step_relationships.job_base_step_id
AND EXCLUDED.step_id = jobstep_to_step_relationships.step_id
对于以下代码,我正在尝试将批量更新插入 table。 table 称为 jobstep_to_step_relationships。如果主键列 "job_base_step_id" 已经存在于 table 中,我希望算法进行更新。
create table jobstep_to_step_relationships
(
job_base_step_id uuid default uuid_generate_v4() not null
constraint jobstep_to_step_relationships_pkey
primary key,
step_id uuid not null,
parent_job_base_step_id uuid not null,
parent_step_id uuid not null,
job_id uuid not null,
order_number integer not null,
is_group boolean not null,
created_at bigint not null,
updated_at bigint not null
);
INSERT INTO jobstep_to_step_relationships
(job_base_step_id, step_id, parent_job_base_step_id, parent_step_id, job_id, order_number,
is_group, created_at, updated_at)
VALUES (, , , , , , , , ),
(, , , , , , , , )
ON CONFLICT (job_base_step_id)
DO UPDATE SET job_base_step_id = EXCLUDED.job_base_step_id,
step_id = EXCLUDED.step_id,
parent_job_base_step_id = EXCLUDED.parent_job_base_step_id,
parent_step_id = EXCLUDED.parent_step_id,
job_id = EXCLUDED.job_id,
order_number = EXCLUDED.order_number,
is_group = EXCLUDED.is_group,
created_at = EXCLUDED.created_at,
updated_at = EXCLUDED.updated_at
WHERE EXCLUDED.job_base_step_id = job_base_step_id
AND EXCLUDED.step_id = step_id
然而,对于以下发布的代码,我收到此错误:
[2019-06-25 13:17:47] [42702] ERROR: column reference "job_base_step_id" is ambiguous
不确定我对文档的解释有误。有人可以指出什么是错的吗?
指定 table 名称以修复歧义:
WHERE EXCLUDED.job_base_step_id = jobstep_to_step_relationships.job_base_step_id
AND EXCLUDED.step_id = jobstep_to_step_relationships.step_id