Saya pikir Anda sangat dekat. Langkah terakhir adalah bergabung dengan pg_type
:
join pg_catalog.pg_type as tp on tp.oid = attr.atttypid
Bidang tp.typname
akan memiliki tipe data.
Kueri berikut mendapatkan tipe data kolom menggunakan namespace (mis., skema) dan nama relasi (mis., tampilan terwujud):
select
attr.attnum,
ns.nspname as schema_name,
cls.relname as table_name,
attr.attname as column_name,
tp.typname as datatype
from pg_catalog.pg_attribute as attr
join pg_catalog.pg_class as cls on cls.oid = attr.attrelid
join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace
join pg_catalog.pg_type as tp on tp.oid = attr.atttypid
where
ns.nspname = 'your_schema'
and cls.relname = 'your_materialized_view'
and attr.attnum >= 1
order by
attr.attnum
Anda harus mengubah 'your_schema'
dan 'your_materialized_view'
.