Find all XML data columns in PostgreSQL database

The query below lists all columns with XML data types in PostgreSQL database.

Query

select col.table_schema,
       col.table_name,
       col.ordinal_position as column_id,
       col.column_name,
       col.data_type
from information_schema.columns col
join information_schema.tables tab on tab.table_schema = col.table_schema
                                   and tab.table_name = col.table_name
                                   and tab.table_type = 'BASE TABLE'
where col.table_schema not in ('information_schema', 'pg_catalog')
      and col.data_type = 'xml'
order by col.table_schema,
         col.table_name,
         col.ordinal_position;

Columns

  • table_schema - name of the database (schema)
  • table_name - name of the table
  • column_id - column position in table
  • column_name - name of the column
  • data_type - type of data

Rows

  • One row represents one column with a XML data type
  • Scope of rows: all columns containing XML data types in the database
  • Ordered by schema name, table name and column position in table

Sample results