Count Rows in Table
pg_count_rowsGet the exact row count for a PostgreSQL table, with optional WHERE filter. Provides precise count for tables of any size.
Instructions
Get exact row count for a table, optionally with a filter condition.
Args:
table: Table name (required)
schema: Schema name (default: public)
where_clause: Optional WHERE condition (without the WHERE keyword)
Returns: JSON: { table, schema, count, where_clause } Markdown: formatted count with filter info
Note: For large tables (>10M rows), pg_table_stats provides a faster estimated count.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name | |
| schema | No | PostgreSQL schema name (default: public) | public |
| where_clause | No | Optional WHERE condition without 'WHERE', e.g. "status = 'active'" |