对于以下代码,我正在尝试向表中批量添加。该表称为jobstep_to_step_relationships。如果主键列“ job_base_step_id”已存在于表中,则我希望算法进行更新。
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 ($1, $2, $3, $4, $5, $6, $7, $8, $9),
($1, $2, $3, $4, $5, $6, $7, $8, $9)
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
不知道我从文档中解释了什么错误。有人可以指出出什么问题吗?
答案 0 :(得分:1)
指定表名以解决歧义:
WHERE EXCLUDED.job_base_step_id = jobstep_to_step_relationships.job_base_step_id
AND EXCLUDED.step_id = jobstep_to_step_relationships.step_id