Count Rows
db_countGet exact row counts for any table with optional filters. Use precise COUNT(*) results for reporting, validation, or confirming scope before bulk operations.
Instructions
Returns the exact number of rows in a table, optionally filtered. This runs an exact COUNT(*) query — not an estimate. Use this when you need a precise count for reporting, validation, or before performing bulk operations.
When to use:
"How many users signed up this week?"
"Count all orders with status pending"
Before bulk deletes, to confirm the scope of the operation
Parameter guidance:
table: the table name (required)
where: optional JSON filter object (same syntax as db_find_many)
Behavioral notes:
Exact COUNT(*) on large tables (millions of rows) may be slow.
On large tables, consider using db_aggregate with a group-by for approximate breakdowns.
Returns an integer count, not a row object.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Name of the table to query | |
| where | No | Optional JSON filter object | |
| database | No | Name of the database to query (from pgautopilot.json). Omit to use the current default database. |