Return the number of bands of a raster
numBands(raster) → integer
The band number accepted by rasterValue and by the operators built on it ranges from 1 to this value.
WITH rast1 AS (
SELECT ST_AddBand(ST_MakeEmptyRaster(3, 3, 0.0, 3.0, 1.0, -1.0, 0.0, 0.0, 4326),
'32BF'::text, 0.0::float8, NULL::float8 ) AS r ), rast2 AS (
SELECT ST_AddBand(r, '32BF'::text, 0.0::float8, NULL::float8) AS r FROM rast1 )
SELECT numBands((SELECT r FROM rast1)) AS num_bands_one,
numBands((SELECT r FROM rast2)) AS num_bands_two;
-- 1 | 2