Hola a todos le pongo este ejemplo para que me comprendan que es lo que
quiero

Esta funcion funciona pero con un parametro duro el de naranja
Pero quiero que sea variable ese parametro intente de la manera comentada el
de verde pero no funciono alguna idea.

--esta funcion estima el tamaño de una tabla segun las filas que
supuestamente generemos

drop FUNCTION sch_desarrollo.fn_estimation_size_table(text,numeric);
CREATE OR REPLACE FUNCTION
sch_desarrollo.fn_estimation_size_table(text,numeric)
  RETURNS text AS
$BODY$
    DECLARE
--select fn_estimation_size_table('table',100000)=======>la tabla y el
numero de registros a estimar
    n_size numeric;
    v_query text;
    v_table alias for $1;
    n_rows alias for $2;
    v_row text;
    v_sch_table text;

BEGIN
    v_row=v_table||'.*';
    v_sch_table='sch_clinica.'||v_table;
    select distinct
round((((n_rows/(8102/(pg_column_size(row(v_row))+4)))*8)::double
precision/1024)::numeric,2) into n_size from sch_clinica.tbl_pais;
    --select distinct
round((((100000/(8102/(pg_column_size(row(tbl_pais.*))+4)))*8)::double
precision/1024)::numeric,2) into n_size from v_sch_table;
    return  'Para '||n_rows::text||' registros se estima '||n_size::text||'
MG en la tabla '||v_table;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;

Consulta:
 select sch_desarrollo.fn_estimation_size_table('tbl_pais',100000);
Resultado:
"Para 100000 registros se estima 3.77 MG en la tabla tbl_pais"

Saludos

-- 
Luis Zevallos
DBA Administrador de  DB & SRVR
Lobo Sistemas S.A.C
tel: +5154958310833
http://www.lobosistemas.com

Responder a