SELECT c.relname AS tablename, a.attname as columnname , ty.typname as typename, ty.typlen as length, ty.typnotnull as notnull FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace LEFT JOIN pg_attribute a ON a.attrelid = c.oid LEFT JOIN pg_type ty ON a.atttypid = ty.oid WHERE c.relkind = 'r'::char and n.nspname='public';