gracias ya lo probe y me funciono muy bien!!!


CREATE OR REPLACE FUNCTION procmty.alinearb(character varying, character
> varying)
>   RETURNS integer AS
> $BODY$
> DECLARE
>  nombre_tabla text:='';
>  solofecha text:='';
> recibo1 timestamp:= NOW()::timestamp;
> *no_rows int;
> ----------------------------------------------------------------------------
> *
>
> BEGIN
>     --select NOW()::timestamp+interval '1 day' into recibo;
>     select 'cadenas2_'||substr(recibo1::text,1,4)
> ||'_'||substr(recibo1::text,6,2) ||'_'||
>     substr(recibo1::text,9,2) into nombre_tabla;
>
>     EXECUTE 'insert into procmty.'||nombre_tabla||'
>      (cadena, id , recibo, puerto, fecha, pid,linea ,fecha2, enviado)  (
>     SELECT * FROM dblink(''host=207.249.166.212 dbname=feria3'',
>     ''SELECT cadena, id , recibo, puerto, fecha, pid,linea ,
>     fecha2, enviado FROM procmty.'||nombre_tabla||' where
>     recibo>='''' '||$1||' '''' and recibo<='''' '||$2||' '''' '')
>     AS t(cadena text, id character varying, recibo timestamp,
>     puerto integer, fecha timestamp, pid integer,linea integer,
>     fecha2 timestamp, enviado integer)
>     where (t.id,t.recibo::timestamp without time zone)::varchar not in (
>     select (id,recibo::timestamp without time zone)::varchar
>     from procmty.'||nombre_tabla||' where recibo>='' '||$1||' '' and
>     recibo<='' '||$2||' '') )';
>
>     *get diagnostics no_rows = ROW_COUNT;
>  -------------------------------------------------*
> *
> *    RETURN *no_rows*;
> -------------------------------------------------------
>
> END;
> $BODY$
>   LANGUAGE 'plpgsql' VOLATILE
>   COST 100;
>

Responder a