0

When I count number of tables in my schema manually, it is 220.

When I count number of views in my schema manually, it is 23.

220 + 23 = 243

However, this query:

select count(distinct tablename) from PG_TABLE_DEF where schemaname='myschema'

returns 305.

Why is there a mismatch?

2
  • Found answer. In PG_TABLE_DEF some rows are created with tablename column ="<table_name>_pkey", when that table has primary key column. So PG_TABLE_DEF contains tables, views and indexes also.
    – Nasrudeen
    Commented Apr 23, 2022 at 8:15
  • You should post this comment as a self-answer so that other can benefit from it; comments often disappear.
    – mustaccio
    Commented Apr 23, 2022 at 11:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.