Returns the pixel values at specified quantiles for a raster object.
Prerequisites
Run ST_StatsQuantile to calculate the quantiles for the raster object before calling ST_Quantile.
Syntax
setof record ST_Quantile(raster raster_obj,
float8[] quantiles default NULL,
cstring bands default '',
boolean exclude_nodata_value default true,
out integer band,
out float8 quantile,
out float8 value)Parameters
Input parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
raster_obj | raster | — | The raster object to query. |
quantiles | float8[] | NULL | The quantiles to return. Valid values: 0.25, 0.5, and 0.75. Pass NULL to return all three quantiles. |
bands | cstring | '' | The serial numbers of the bands to include. Supported formats: '0-2' (range) and '1,2,3' (list). Serial numbers start from 0. An empty string (default) includes all bands. |
exclude_nodata_value | boolean | true | Specifies whether to exclude NoData values from the query. |
Output parameters
| Parameter | Type | Description |
|---|---|---|
band | integer | The serial number of the band. |
quantile | float8 | The quantile value. |
value | float8 | The pixel value at the quantile. |
Examples
Example 1: Return the pixel value at the 0.25 quantile for all bands (bands 0–2).
SELECT (ST_Quantile(rast, ARRAY[0.25], '0-2', true)).* FROM rat_quantile WHERE id = 1;Output:
band | quantile | value
------+----------+-------
0 | 0.25 | 11
1 | 0.25 | 10
2 | 0.25 | 50
(3 rows)Example 2: Return pixel values at all quantiles (0.25, 0.5, 0.75) for band 0.
SELECT (ST_Quantile(rast, NULL, '0', true)).* FROM rat_quantile WHERE id = 1;Output:
band | quantile | value
------+----------+-------
0 | 0.25 | 11
0 | 0.5 | 11
0 | 0.75 | 65
(3 rows)