-- Function: get_columnas(character varying)
-- DROP FUNCTION get_columnas(character varying);
CREATE OR REPLACE FUNCTION get_columnas(tabla character varying)
RETURNS SETOF columnas AS
$BODY$
declare
resultado columnas%rowtype;
nomb_tabla character varying;
begin
nomb_tabla = '^(' || 'm_product' || ')$';
drop table if exists tmp_columnas;
create table tmp_columnas as
SELECT
a.attname as "Column",
pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
FROM
pg_catalog.pg_attribute a
WHERE
a.attnum > 0
AND NOT a.attisdropped
AND a.attrelid = (
SELECT c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ nomb_tabla
AND pg_catalog.pg_table_is_visible(c.oid)
)
;
for resultado in execute
'select t.* from tmp_columnas t;'
loop
return next resultado;
end loop;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION get_columnas(character varying)
OWNER TO adempiere;
No hay comentarios:
Publicar un comentario