WITH columns AS (SELECT nspname AS table_schema, relname AS table_name,
CASE WHEN relkind='r' THEN 'BASE TABLE'
WHEN relkind='m' THEN 'MATERIALIZED VIEW'
END AS table_type,
attname AS column_name,
coalesce(domain_type.typname, pg_type.typname) AS data_type
FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid
INNER JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid
INNER JOIN pg_type ON pg_attribute.atttypid =pg_type.oid
LEFT JOIN pg_type AS domain_type ON domain_type.oid=pg_type.typbasetype
WHERE attnum>=1
AND relkind IN ('r','m')
AND nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
text_search_cols AS (SELECT table_schema, table_name, table_type, array_agg(column_name::text) AS column_name
FROM columns
WHERE data_type IN ('tsvector')
GROUP BY table_schema, table_name, table_type)
SELECT table_schema, table_name, table_type, column_name
FROM text_search_cols
ORDER BY table_schema, table_name, table_type;