-- -- column_exists/2 -- create or replace function column_exists( character varying, character varying ) returns bool as $$ declare column_exists__table_name alias for $1; column_exists__column_name alias for $2; begin return count(*) > 0 from pg_class c, pg_attribute a where c.relname = lower(column_exists__table_name) and c.oid = a.attrelid and a.attname = lower(column_exists__column_name); end;$$ language plpgsql;