select distinct t.field from ( SELECT c.relname,a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a .atttypmod AS lengthvar,a.attnotnull AS notnull from pg_class c,pg_attribute a,pg_type t where c.relname like '%stat_plan_result_%' and c.relname not like '%seq%' and a.attnum>0 and a.attrelid=c.oid and a.atttypid=t.oid and a.attname not in ('planid','rtime','cell') ) t