Skip to content

Instantly share code, notes, and snippets.

@martinov
Last active August 24, 2022 14:57
Show Gist options
  • Save martinov/fbe1a29792bf1482cd859dc51631e6d5 to your computer and use it in GitHub Desktop.
Save martinov/fbe1a29792bf1482cd859dc51631e6d5 to your computer and use it in GitHub Desktop.
List all JSON and JSONB fields in given Postgres DB
-- Source: https://dataedo.com/kb/query/postgresql/find-all-json-columns
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', 'graphile_worker')
and col.data_type in ('json', 'jsonb')
order by col.table_schema,
col.table_name,
col.ordinal_position;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment