All Products
Search
Document Center

PolarDB:ST_SubRaster

Last Updated:Mar 28, 2026

Transforms a pyramid level or specific bands from a raster object and returns the result as a new raster object.

Syntax

raster ST_SubRaster(raster raster_obj,
           integer pyramidLevel DEFAULT 0,
           cstring bands DEFAULT '',  /* All bands */
           cstring storageOption DEFAULT '')

Parameters

ParameterTypeDefaultDescription
raster_objrasterThe source raster object to extract from.
pyramidLevelinteger0The pyramid level to transform.
bandscstring''The bands to extract. Accepts an integer range (e.g., '0-2') or a comma-separated list (e.g., '1,2,3'). Band indexes start at 0. An empty string extracts all bands.
storageOptioncstring''A JSON string that controls how the new raster object is stored.

storageOption fields

FieldTypeDefaultDescription
chunkingBooleanSame as sourceWhether to store the new raster object in chunks.
chunkdimStringSame as sourceChunk dimensions. Takes effect only when chunking is true.
chunktableString'' (empty)Name of the chunk table. By default, a temporary chunk table with a random name is created and is only valid for the current session. Specify a table name to save the raster object permanently.
compressionStringSame as sourceCompression format. Supported values: None, JPEG, Zlib, PNG, LZO, LZ4.
qualityIntegerSame as sourceJPEG image quality. Takes effect only when compression is JPEG.
interleavingStringSame as sourceInterleaving type. Supported values: bip (band interleaved by pixel, BIP), bil (band interleaved by line, BIL), bsq (band sequential, BSQ).
endianStringSame as sourceByte order. Supported values: NDR (little endian format), XDR (big endian format).

Usage notes

  • Persistent storage: By default, the output raster is stored in a temporary chunk table that expires at the end of the session. To save the output permanently, specify a chunktable name in storageOption.

  • Band index: Band indexes start at 0. Use the range syntax ('0-2') or the list syntax ('1,2,3') to select multiple bands.

Example

Extract pyramid level 1 and bands 0 through 2 from a raster, saving the result to a permanent chunk table:

SELECT ST_SubRaster(rast, 1, '0-2', '{"chunktable":"chunk_table", "chunking":true}')
FROM raster_sub
WHERE id = 1;