Is there a limit on the maximum number of bands you can store in a postgis raster?

I cannot find documentation on this. As far as I can remember, a geotiff allows up to the max short integer (so about 32000) bands. Is it safe to assume PGRaster is the same?

All I can find is this page


which seems to suggest that the max number of bands is equal to the limit of an unsigned int16 (65000 or so)...?

In any case, of course we dont need to use so many bands but we are looking at creating a raster with up to 100 different values for each cell, so I just want to be sure that the max number of bands is not something crazy like 3!


The exact answer is that the number of bands in a raster is stored in a 2-byte integer, so 65536 (indexes 0 to 65535) possible bands.

There is one additional restriction which is the maximum band index value supported for out-db rasters and that is 256 (indexes 0 to 255).


I suspect things have changed since those docs were written. If you look at the table definition by running \d raster_columns from a psql prompt, you will see:

       View "public.raster_columns"
  Column      |        Type        | Modifiers 
r_table_catalog  | name               | 
r_table_schema   | name               | 
r_table_name     | name               | 
r_raster_column  | name               | 
srid             | integer            | 
scale_x          | double precision   | 
scale_y          | double precision   | 
blocksize_x      | integer            | 
blocksize_y      | integer            | 
same_alignment   | boolean            | 
regular_blocking | boolean            | 
num_bands        | integer            | 
pixel_types      | text[]             | 
nodata_values    | double precision[] | 
out_db           | boolean[]          | 
extent           | geometry           | 

which shows num_bands an an integer, ie, with a max value of 2147483647, which should be enough for a few years -- remember Y2K and IP addresses running out.

Playing around a bit with one of the examples on the ST_AddBand page, suggests that the limit is definitely greater than 3 :D

   FROM ST_BandMetadata(
         ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
                 ROW(1, '8BUI', 255, 0),
                 ROW(2, '16BUI', 1, 2),
                 ROW(3, '32BUI', 100, 12),
                 ROW(4, '32BUI', 100, 12),
                 ROW(5, '32BUI', 100, 12),
                 ROW(6, '32BUI', 100, 12),
                 ROW(7, '32BUI', 100, 12),
                 ROW(8, '32BUI', 100, 12),
                 ROW(9, '32BUI', 100, 12),
                 ROW(10, '32BUI', 100, 12)

As I recall, I think in PostGIS 2.0, the limit was 256 and in 2.1 it's much higher (Not sure if there is a limit actually, but your assumption about integer limitation sounds about right).

Anyway in either case if all you plan to have is 100 bands, you should be fine.


The example in the first section of the current raster documentation still has nBands as a 16-bit unsigned, so that would limit it to 65,535 bands. The only other possibility is that there is a newer version of the raster type that's not documented in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.