Verificar se Campo Existe (Catálogo)

Verificar se Campo Existe (Catálogo)

Você pode acessar as tabelas do catalogo e verificar se o campo existe.

Por exemplo:

SELECT a.relname AS Tabela, b.attname AS Campo
FROM pg_class a
JOIN pg_attribute b ON (b.attrelid = a.relfilenode)
WHERE  b.attstattarget = -1 AND
	a.relname = <TABELA> AND  b.attname = <CAMPO>;
IF NOT FOUND THEN
**** existe o campo
ELSE
**** não existe o campo
END IF;
Tags: