0

I am attempting to run a PostgreSQL statement to query approximate table size count estimate using the following statement:

SELECT reltuples as approximate_row_count FROM pg_class WHERE relname = 'table_name';

ref: Count estimate (PostgreSQL | Wiki)

However, my query is returning two rows, one with a size and one with zero. Why?

1
  • This is not a typo question, not sure why the close votes...I put it here because googling for this issue yielded no answers... – rogerdpack Aug 5 '20 at 15:22
1

Turns out I had the same table (same name) within two different schemas. So each had an entry in pg_class.

Work around from the wiki page is SELECT * FROM pg_class WHERE oid = 'schema_name.table_name'::regclass;

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.