All Products
Search
Document Center

AnalyticDB:ST_ColorTable

Last Updated:Mar 28, 2026

Returns the color table of a specified band in a raster object, encoded as JSON. Returns null if the band has no color table.

Syntax

text ST_ColorTable(raster raster_obj, integer band);

Parameters

ParameterTypeDescription
raster_objrasterThe raster object.
bandintegerThe band index. Starts from 0.

Description

The returned JSON object has the following top-level fields:

FieldTypeDescription
compsCountintegerThe number of color components. 3 = three components; 4 = four components.
entriesarrayThe color table entries. Each entry maps a pixel value to its color components.

Each entry in entries has the following fields:

FieldDescription
valueThe pixel value.
c1Component 1.
c2Component 2.
c3Component 3.
c4Component 4. Present only when compsCount is 4.

JSON format

3-component:

{
  "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}
  ]
}

4-component:

{
  "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}
  ]
}

Examples

Retrieve the color table for band 0 of a raster object:

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

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}
  ]
}