All Products
Search
Document Center

ApsaraDB RDS:ST_ColorTable

Last Updated:Mar 28, 2026

Returns the color table of a raster band as a JSON string.

Syntax

text ST_ColorTable(raster raster_obj, integer band);

Parameters

ParameterDescription
raster_objThe raster object.
bandThe sequence number of the band. Band numbering starts from 0.

Return value

A JSON string with the following structure:

FieldDescription
compsCountThe number of color components: 3 or 4.
entriesAn array of color table entries. Each entry maps a pixel value to its color components.
valueThe pixel value.
c1Color component 1.
c2Color component 2.
c3Color component 3.
c4Color component 4. Present only when compsCount is 4.

Four color components:

{
  "compsCount": 4,
  "entries": [
    {"value": 0, "c1": 0, "c2": 0, "c3": 0,   "c4": 255},
    {"value": 1, "c1": 0, "c2": 0, "c3": 85,  "c4": 255},
    {"value": 2, "c1": 0, "c2": 0, "c3": 170, "c4": 255}
  ]
}

Three color components:

{
  "compsCount": 3,
  "entries": [
    {"value": 0, "c1": 0, "c2": 0, "c3": 0},
    {"value": 1, "c1": 0, "c2": 0, "c3": 85},
    {"value": 2, "c1": 0, "c2": 0, "c3": 170}
  ]
}
If the band does not have a color table, the function returns null.

Examples

Query the color table of band 0 from a raster object:

SELECT ST_ColorTable(raster_obj, 0) FROM raster_table WHERE id = 1;

Expected output:

{
  "compsCount": 3,
  "entries": [
    {"value": 0, "c1": 0, "c2": 0, "c3": 0},
    {"value": 1, "c1": 0, "c2": 0, "c3": 85},
    {"value": 2, "c1": 0, "c2": 0, "c3": 170}
  ]
}