All Products
Search
Document Center

PolarDB:ST_SummaryStats

Last Updated:Mar 28, 2026

Calculates statistics for a specified set of bands in a raster object and writes the results back to the raster.

Syntax

raster ST_SummaryStats(raster raster_obj)
raster ST_SummaryStats(raster raster_obj, cstring statsOption)
raster ST_SummaryStats(raster raster_obj, cstring bands, cstring statsOption)

Parameters

ParameterTypeDescription
raster_objrasterThe raster object to compute statistics for.
bandscstringThe bands to compute statistics for. Accepts an integer array or an integer range. Band sequence numbers start at 0. Examples: '0', '1-3', '1,2,3'.
statsOptionscstringA JSON string that specifies the statistics options. See statsOptions.

statsOptions

ParameterTypeDefaultDescription
approxbooleantrueSpecifies whether to use sampling to estimate statistics. true: use sampling (faster, but results may be approximate). false: compute exact statistics across all pixels.
By default, approx is true. Set "approx": false for exact results. Sampling is faster on large rasters but the statistics may differ slightly from exact values.

Examples

All examples use an UPDATE statement to write the computed statistics back to the raster object.

Calculate statistics for all bands using default options (sampling enabled):

UPDATE raster_obj SET raster_obj=ST_SummaryStats(raster_obj) WHERE id = 1;

Calculate exact statistics for bands 0 through 2:

UPDATE rast SET rast=ST_SummaryStats(rast,'0-2','{"approx":false}') WHERE id = 1;

Calculate exact statistics for all bands without specifying a band range:

UPDATE rast SET rast=ST_SummaryStats(rast,'{"approx":false}') WHERE id = 1;