Skip to content

Commit 521f893

Browse files
authored
Query to check not valid constraints (#34)
* Query to check not valid constraints * request approve
1 parent 6a5b823 commit 521f893

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sql/check_not_valid_constraints.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2019-2024. Ivan Vakhrushev and others.
3+
* https://github.com/mfvanek/pg-index-health-sql
4+
*
5+
* Licensed under the Apache License 2.0
6+
*/
7+
8+
select
9+
t.relname as table_name, -- Name of the table
10+
c.conname as constraint_name, -- Name of the constraint
11+
c.contype as constraint_type -- Type of the constraint
12+
from
13+
pg_catalog.pg_constraint c
14+
join pg_catalog.pg_class t on t.oid = c.conrelid
15+
join pg_catalog.pg_namespace n on n.oid = t.relnamespace
16+
where
17+
not c.convalidated -- Constraints that have not yet been validated
18+
and c.contype in ('c', 'f') -- Focus on check and foreign key constraints
19+
and n.nspname = :schema_name_param::text; -- Make the query schema-aware

0 commit comments

Comments
 (0)