All Products
Search
Document Center

PolarDB:ST_ComputeStatistics

Last Updated:Mar 28, 2026

Computes statistics for a raster object, including histogram and percentile data.

Syntax

raster ST_ComputeStatistics(raster raster_obj,
                            cstring sampleOption DEFAULT '{}')

raster ST_ComputeStatistics(raster raster_obj,
                            cstring bands,
                            cstring sampleOption DEFAULT '{}',
                            cstring parallelOption DEFAULT '{}')

Parameters

ParameterDescription
raster_objThe raster object to compute statistics for.
bandsThe band IDs to process. Use comma-separated values and ranges, for example '0,1-3,6,8'. Band IDs start from 0. Set to '' to process all bands.
sampleOptionA JSON string that configures sampling behavior. See sampleOption parameters.
parallelOptionA JSON string that configures parallel processing. See parallelOption parameters.

sampleOption parameters

ParameterTypeDefaultDescription
approxBooleanfalseSpecifies whether to use approximate sampling. When true, the sampling method is used. Results may be less accurate.
factorinteger4The sampling factor — the number of pixels per sampling unit. Valid values: any positive integer. Applies only when approx is true.
exclusive_nodataBooleantrueSpecifies whether to include NoData values. Valid values: true and false.

parallelOption parameters

ParameterTypeDefaultDescription
parallelintegerganos.parallel.degreeThe degree of parallelism for the computation. Valid values: 1 to 64.

Examples

Use default settings (all bands, exact statistics):

UPDATE raster_table
SET raster_obj = ST_ComputeStatistics(raster_obj)
WHERE id = 1;

Specify bands and disable approximate sampling:

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

Disable approximate sampling (no band filter):

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

Specify bands, enable approximate sampling with a custom factor, and set the degree of parallelism:

UPDATE raster_table
SET raster_obj = ST_ComputeStatistics(raster_obj, '0-2', '{"approx":true, "factor":5}', '{"parallel":4}')
WHERE id = 1;