
insertart registro a otra base de dato por dblink
Publicado por tayshaun (6 intervenciones) el 11/02/2022 15:38:34
Buenos dias Colegas, estoy tratando de crear un cursor en postgresql, para asi insertar esos registro en otro servidor por dblink, la funcion corre bien pero cuando ejecuto mi funcion me dice que la tabla a la que voy a insertar no existe donde quiero insertar (esto lo estoy haciendo desde un servidor cliente que va a insertar la data al principal):
create or replace function public.insertar_reg(
)
returns void
language 'plpgsql'
cost 100
volatile parallel UNSAFE
as $BODY$
declare
v_id prueba_1%rowtype;
v_found_error varchar(30):='no data found';
prueba_cursor cursor for
select * from prueba_1;
begin
open prueba_cursor;
loop
fetch prueba_cursor into v_id;
insert into central
select * from dblink('dbname=center port=5432 host=192.168.56.3 user=postgres password=123', '
select compania,nombre,fecha,estatus from central')
as cust (compania integer, nombre varchar(30),fecha date,estatus varchar(5))
where not exists (select compania from central
where compania=compania
group by compania);
end loop;
update central
set estatus='C'
where fecha between '01-feb-2022' and '02-feb-2022'
and fecha <= now() - interval '7 day';
exception
when no_data_found then
raise exception 'film % not found', v_found_error;
end;
$BODY$;
========================
este es el error que presenta cuando ejecuto la function
ERROR: relation "central" does not exist
LINE 1: insert into central
^
QUERY: insert into central
select * from dblink('dbname=center port=5432 host=192.168.56.3 user=postgres password=123', '
select compania,nombre,fecha,estatus from central')
as cust (compania integer, nombre varchar(30),fecha date,estatus varchar(5))
where not exists (select compania from central
where compania=compania
group by compania)
CONTEXT: PL/pgSQL function insertar_reg() line 11 at SQL statement
SQL state: 42P01
create or replace function public.insertar_reg(
)
returns void
language 'plpgsql'
cost 100
volatile parallel UNSAFE
as $BODY$
declare
v_id prueba_1%rowtype;
v_found_error varchar(30):='no data found';
prueba_cursor cursor for
select * from prueba_1;
begin
open prueba_cursor;
loop
fetch prueba_cursor into v_id;
insert into central
select * from dblink('dbname=center port=5432 host=192.168.56.3 user=postgres password=123', '
select compania,nombre,fecha,estatus from central')
as cust (compania integer, nombre varchar(30),fecha date,estatus varchar(5))
where not exists (select compania from central
where compania=compania
group by compania);
end loop;
update central
set estatus='C'
where fecha between '01-feb-2022' and '02-feb-2022'
and fecha <= now() - interval '7 day';
exception
when no_data_found then
raise exception 'film % not found', v_found_error;
end;
$BODY$;
========================
este es el error que presenta cuando ejecuto la function
ERROR: relation "central" does not exist
LINE 1: insert into central
^
QUERY: insert into central
select * from dblink('dbname=center port=5432 host=192.168.56.3 user=postgres password=123', '
select compania,nombre,fecha,estatus from central')
as cust (compania integer, nombre varchar(30),fecha date,estatus varchar(5))
where not exists (select compania from central
where compania=compania
group by compania)
CONTEXT: PL/pgSQL function insertar_reg() line 11 at SQL statement
SQL state: 42P01
Valora esta pregunta


0