【发布时间】:2022-01-26 14:20:14
【问题描述】:
我正在尝试使用另一个表的字段在一个表中执行 upsert,我尝试使用 On Conflict “下面的代码”,但它总是给我这个错误:“Errore SQL [42601]: ERROR : “from”处或附近的语法错误 位置:926" 但如果我要删除“从编排编排”,它会给我这个异常:“Errore SQL [42P01]:错误:缺少表“编排”的 FROM 子句条目 位置:334" 有人可以帮我吗?
insert into ro_banche (id_banca,code_abi, code_fisc, desc_banca, desc_banca_rid, data_attivaz, data_cessaz, code_abi_nuovo, code_abi_trasf, code_abi_cor, code_abi_nocor, code_abi_giro, flag_tipo_ades, code_tipo_istituto, data_modifica, utente_modifica)
select * from orchestrate
ON CONFLICT (code_abi) DO
update set code_fisc = orchestrate.code_fisc, desc_banca = orchestrate.desc_banca, desc_banca_rid = orchestrate.desc_banca_rid, data_attivaz = orchestrate.data_attivaz, data_cessaz = orchestrate.data_cessaz, code_abi_nuovo = orchestrate.code_abi_nuovo, code_abi_trasf = orchestrate.code_abi_trasf, code_abi_cor = orchestrate.code_abi_cor, code_abi_nocor = orchestrate.code_abi_nocor, code_abi_giro = orchestrate.code_abi_giro, flag_tipo_ades = orchestrate.flag_tipo_ades, code_tipo_istituto = orchestrate.code_tipo_istituto, data_modifica = orchestrate.data_modifica, utente_modifica = orchestrate.utente_modifica
from orchestrate orchestrate
where (ro.code_abi = orchestrate.code_abi);
【问题讨论】:
-
为什么在 FROM 子句中写两次
orchestrate?只有一次应该没问题。 -
您不能使用“select *”,您需要以与您定义的目标的列列表匹配的顺序明确列出列。否则,您的流程如何知道源中的哪些列需要插入目标中的哪些列?
标签: sql postgresql