Buen día.

Necesito crear un campo en todas que no tengan un campo en concreto para ello 
tengo 2 funciones, el problema se da es que la funcion 
campo_check_fnc me devuelve también las vista y se produce un error.

Como puedo fitrar que solo me devuelva tablas.

CREATE OR REPLACE FUNCTION public.campo_check_fnc() 
RETURNS void AS 
$BODY$ 
DECLARE rs RECORD; 
BEGIN 
FOR rs IN 
( 
 SELECT table_schema, table_name 
  FROM information_schema.columns 
   Where table_schema Not In ('pg_catalog', 'information_schema', 'public', 
'prueba') 
     And table_schema || table_name Not IN 
   (Select t.table_schema || t.table_name 
     From 
      ( 
       SELECT table_schema, table_name, column_name = 'mi_campo' As 
existe_campo 
        FROM information_schema.columns 
         Where table_schema Not In ('pg_catalog', 'information_schema', 
'public', 'prueba') 
       ) t 
      Where t.existe_campo = TRUE 
   ) 
 GROUP BY table_schema, table_name 
  ORDER BY table_schema, table_name ) LOOP 

PERFORM * FROM public.campo_crea_fnc(rs.table_schema::VARCHAR, 
rs.table_name::VARCHAR); 
END LOOP; 
END; 
$BODY$ 
LANGUAGE plpgsql VOLATILE 
COST 100; 
ALTER FUNCTION public.migracion_campo_check_fnc() 
OWNER TO postgres; 




CREATE OR REPLACE FUNCTION public.campo_crea_fnc( 
p_schema character varying, 
p_tabla character varying) 
RETURNS void AS 
$BODY$ 
BEGIN 

EXECUTE 'ALTER TABLE ' || p_schema || '.' || p_tabla || ' ADD COLUMN mi_campo 
CHAR(2) DEFAULT ''NO'''; 
END; 
$BODY$ 
LANGUAGE plpgsql VOLATILE 
COST 100; 

Saludos.
Mauricio

-
Enviado a la lista de correo pgsql-es-ayuda (pgsql-es-ayuda@postgresql.org)
Para cambiar tu suscripci�n:
http://www.postgresql.org/mailpref/pgsql-es-ayuda

Responder a