-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added query to find columns of json type. Use jsonb instead.
- Loading branch information
Ivan Vakhrushev
committed
Aug 13, 2022
1 parent
54d073f
commit 6696b70
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2019-2022. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health-sql | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
-- Finds columns of type 'json'. Use 'jsonb' instead. | ||
-- | ||
-- See also https://www.postgresql.org/docs/current/datatype-json.html | ||
-- and https://medium.com/geekculture/postgres-jsonb-usage-and-performance-analysis-cdbd1242a018 | ||
select | ||
t.oid::regclass::text as table_name, | ||
col.attname::text as column_name, | ||
col.attnotnull as column_not_null | ||
from pg_catalog.pg_class t | ||
join pg_catalog.pg_namespace nsp on nsp.oid = t.relnamespace | ||
join pg_catalog.pg_attribute col on (col.attrelid = t.oid) | ||
where | ||
t.relkind = 'r' and | ||
col.attnum > 0 and /* to filter out system columns such as oid, ctid, xmin, xmax, etc.*/ | ||
col.atttypid::regtype::text = 'json' and | ||
nsp.nspname = :schema_name_param::text | ||
order by t.oid::regclass::text, col.attname::text; |