PostGISBounding Box

ST_EstimatedExtent

What is ST_EstimatedExtent?

ST_EstimatedExtent is a PostGIS function that returns an approximate box2d extent for a geometry column by reading PostgreSQL's table statistics rather than scanning the table. It is much faster than ST_Extent but is only as accurate as the last ANALYZE.

SQL
1ST_EstimatedExtent(text schema_name, text table_name, text geocolumn_name) → box2d
2ST_EstimatedExtent(text table_name, text geocolumn_name) → box2d
3ST_EstimatedExtent(text schema_name, text table_name, text geocolumn_name, boolean parent_only) → box2d

If statistics are missing or stale, the function returns NULL.

When would you use ST_EstimatedExtent?

Use ST_EstimatedExtent for UI use cases where you need a fast zoom-to-layer extent — map applications, tile server initialization, BBOX defaults. It avoids a full table scan, which is essential for tables with millions of rows. Run ANALYZE your_table after bulk loads to keep the estimate fresh.

SQL
SELECT ST_EstimatedExtent('public', 'parcels', 'geom') AS bbox;

FAQs

How accurate is ST_EstimatedExtent?

Accuracy depends entirely on PostgreSQL statistics. Right after ANALYZE, the extent is close to the true extent. As data drifts, the estimate lags. For a guaranteed-accurate answer use ST_Extent, which scans every row.

When does ST_EstimatedExtent return NULL?

When PostgreSQL has no statistics for the column — typically after CREATE TABLE without an ANALYZE, or when the table is empty. Run ANALYZE schema.table and re-call the function.

Does it work on views or materialized views?

No — ST_EstimatedExtent relies on the statistics catalog entry for the underlying column, which exists only on physical tables and matviews with collected statistics. For views, you have to fall back to ST_Extent.

What's the difference between ST_EstimatedExtent and ST_Extent?

ST_Extent is an aggregate that scans each geometry in the query's FROM/WHERE and returns an exact extent — correct but potentially slow. ST_EstimatedExtent reads metadata and runs in milliseconds regardless of table size, at the cost of accuracy.