So I got this error, I put the alias at num_documento (codigo “a.num_documento”) but Postgres says num_documento doesn’t exist.
ERROR: la referencia a la columna �num_documento� es ambigua
Where: PL/pgSQL function "insertar_carga_giros"
line 145 at sentencia SQ???
–Query function insertar_carga_giros
insert into bdsinc."codigo"(num_documento,id_tip_dcto,id_deudor)
select distincta.num_documento,b.id_tip_dcto,b.id_deudor
from bdsinc."carga" a
left join bdsinc."tb_deudor" b
on a.num_documento=b.num_dcto
and a.id_tip_dcto=b.id_tip_dcto
where b.id_deudor is not null and validacion=1;
How can I do an insert with select join inside in PostgreSQL?
This
INSERTstatement looks ok. You probably defined a variable namenum_documentoin your function that conflicts with the column name. Maybe anINparameter?Try renaming that variable.
Assuming that you actually have: