Я пытаюсь получить отдельную запись с комбинацией из пяти столбцов, и я получаю сообщение об ошибке. Может кто-нибудь, пожалуйста, объясните, где я допустил ошибку. вначале я скомпилировал функцию и выполнил ее, а также проверил результаты, но не знаю, почему сейчас отображается ошибка
create or replace function vt_pc_gold_partner() returns void as $$
declare
rec_vt_pc_unique_id record;
cur_vt_pc_unique_id cursor for select * from ( select
Coalesce("Source System",'00') "Source System",
Coalesce("Group Number",'00') "Group Number",
Coalesce("Partner Party Id",'00') "Partner Party Id",
Coalesce("Translated Contact Email",'00') "Translated Contact Email",
count(1)
from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
group by
"Source System",
"Group Number",
"Partner Party Id",
"Translated Contact Email"
having count(1) = 1) a;
rec_vt_pc_greater_then_one record;
cur_vt_pc_greater_then_one cursor for select * from ( select
Coalesce("Source System",'00') "Source System",
Coalesce("Group Number",'00') "Group Number",
Coalesce("Partner Party Id",'00') "Partner Party Id",
Coalesce("Translated Contact Email",'00') "Translated Contact Email",
count(1)
from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
group by
"Source System",
"Group Number",
"Partner Party Id",
"Translated Contact Email"
having count(1) > 1) a;
max_last_update_var varchar(2000);
max_creationdate_var varchar(2000);
l_count numeric;
l_creation_count numeric;
rec_vt_pc_greater_then_LUPD_one record;
cur_vt_pc_greater_then_LUPD_one cursor for select * from ( select
Coalesce("Source System",'00') "Source System",
Coalesce("Group Number",'00') "Group Number",
Coalesce("Partner Party Id",'00') "Partner Party Id",
Coalesce("Translated Contact Email",'00') "Translated Contact Email",
Coalesce("Partner Last Update Date Ref",'00') "Partner Last Update Date Ref",
count(1)
from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
group by
"Source System",
"Group Number",
"Partner Party Id",
"Translated Contact Email",
"Partner Last Update Date Ref"
having count(1) > 1) a;
max_serial_no varchar(2000);
begin
TRUNCATE TABLE VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC_TEMP;
for rec_vt_pc_unique_id in cur_vt_pc_unique_id
loop
insert into VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC_TEMP select * from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_unique_id."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_unique_id."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_unique_id."Partner Party Id"
AND Coalesce("Translated Contact Email",'00') = rec_vt_pc_unique_id."Translated Contact Email"
;
end loop;
for rec_vt_pc_greater_then_one in cur_vt_pc_greater_then_one
loop
select max("Partner Last Update Date Ref") into max_last_update_var from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_one."Partner Party Id"
group by "Source System",
"Group Number",
"Partner Party Id";
select count(1) into l_count from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC where
Coalesce("Source System",'00') = rec_vt_pc_greater_then_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_one."Partner Party Id" and
Coalesce("Partner Last Update Date Ref",'00') = max_last_update_var;
if l_count = 1
then
insert into VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC_TEMP select * from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_one."Partner Party Id"
AND Coalesce("Translated Contact Email",'00') = rec_vt_pc_greater_then_one."Translated Contact Email" and
Coalesce("Partner Last Update Date Ref",'00') = max_last_update_var
;
end if;
end loop;
FOR rec_vt_pc_greater_then_LUPD_one IN cur_vt_pc_greater_then_LUPD_one
LOOP
select max("Partner Creation Date Ref") into max_creationdate_var from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_LUPD_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_LUPD_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Party Id" and
Coalesce("Partner Last Update Date Ref",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Last Update Date Ref"
group by "Source System",
"Group Number",
"Partner Party Id",
"Partner Last Update Date Ref";
select count(1) into l_creation_count from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC where
Coalesce("Source System",'00') = rec_vt_pc_greater_then_LUPD_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_LUPD_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Party Id" and
Coalesce("Partner Last Update Date Ref",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Last Update Date Ref" and
Coalesce("Partner Creation Date Ref",'00') = max_creationdate_var;
if l_creation_count = 1
then
insert into VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC_TEMP select * from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_LUPD_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_LUPD_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Party Id"
AND Coalesce("Translated Contact Email",'00') = rec_vt_pc_greater_then_LUPD_one."Translated Contact Email" and
Coalesce("Partner Last Update Date Ref",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Last Update Date Ref" and
Coalesce("Partner Creation Date Ref",'00') = max_creationdate_var;
else
select max("appMDM Sl No (Partner)") into max_serial_no from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_LUPD_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_LUPD_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Party Id" and
Coalesce("Partner Last Update Date Ref",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Last Update Date Ref"
and Coalesce("Partner Creation Date Ref",'00') = max_creationdate_var
group by "Source System",
"Group Number",
"Partner Party Id",
"Partner Last Update Date Ref",
"Partner Creation Date Ref";
insert into VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC_TEMP select * from VT_PC_DE_DUP_CONSOLIDATED_JAN_22_INC
where Coalesce("Source System",'00') = rec_vt_pc_greater_then_LUPD_one."Source System"
AND Coalesce("Group Number",'00') = rec_vt_pc_greater_then_LUPD_one."Group Number" AND
Coalesce("Partner Party Id",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Party Id"
AND Coalesce("Translated Contact Email",'00') = rec_vt_pc_greater_then_LUPD_one."Translated Contact Email" and
Coalesce("Partner Last Update Date Ref",'00') = rec_vt_pc_greater_then_LUPD_one."Partner Last Update Date Ref" and
Coalesce("Partner Creation Date Ref",'00') = max_creationdate_var and
"appMDM Sl No (Partner)" = max_serial_no;
end if;
end loop;
end;
$$LANGUAGE plpgsql;
ERROR: INSERT has more expressions than target columns
Where: PL/pgSQL function vt_pc_gold_partner() line 63 at SQL statement