How to make an Insert with select using bdlink

Asked

Viewed 19 times

0

I need to do an Insert along with select looking for data from another database, for this I’m using dblink, but I’m not getting, I use pgadmin4

declare
    insertCad RECORD;
begin   
    for insertCad in SELECT * FROM dblink('dbname=empresa host=ip user=postgres password=senha',
                                           'select nfecadcod, nfecadnome, nfedte, nfecnpjcpf, nfecadie, nfecademail, nfecadtel, nfecadcep, nfecadend, nfecadendn, nfecadcidnom, nfecadcidcod, nfecaduf, nfecadpais 
                                            from fis.nfe 
                                            where nfecadcod = 999999') 
    as data (nfecadcod integer, nfecadnome char(60), nfedte date, nfecnpjcpf char(18), nfecadie char(20), nfecademail char(60), nfecadtel char(20), nfecadcep char(9), nfecadend char(60), nfecadendn char(10), nfecadcidnom char(60), nfecadcidcod char(7), nfecaduf char(2), nfecadpais char(4)) loop
        insert into cad.cad (cadcod, cadnome, caddata, cadcnpjcpf, cadie, cademail, cadtel1, cadcep, cadend, cadendnum, cadcidnome, cadcidcod, caduf, cadpaiscod)
        select nextval('cad.seq_cad_cad_cadcod'), insertCad.nfecadnome, insertCad.nfedte, insertCad.nfecnpjcpf, insertCad.nfecadie, insertCad.nfecademail, insertCad.nfecadtel, ninsertCad.fecadcep, insertCad.nfecadend, insertCad.nfecadendn, insertCad.nfecadcidnom, insertCad.nfecadcidcod, insertCad.nfecaduf, insertCad.nfecadpais
        from insertcad
        where insertCad.nfecadcod = 999999;
    end loop;
end;

I think the problem is no from, I’ve tried some things and I haven’t been successful I need to solve this question, I’m grateful to anyone who can help me

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.