ST_BandMetaData — 返回特定栅格波段的基本元数据。如果未指定波段号,则假定为波段 1。
(1) record ST_BandMetaData(raster rast, integer band=1);
(2) record ST_BandMetaData(raster rast, integer[] band);
返回关于栅格波段的基本元数据。返回的列包括:pixeltype、nodatavalue、isoutdb、path、outdbbandnum、filesize、filetimestamp。
| ![[Note]](../images/note.png)  | |
| 如果栅格不包含任何波段,则会抛出错误。 | 
| ![[Note]](../images/note.png)  | |
| 如果波段没有 NODATA 值,则 nodatavalue 为 NULL。 | 
| ![[Note]](../images/note.png)  | |
| 如果 isoutdb 为 False,则 path、outdbbandnum、filesize 和 filetimestamp 为 NULL。 如果禁用 outdb 访问,则 filesize 和 filetimestamp 也将为 NULL。 | 
增强功能:2.5.0 版本开始为 outdb 栅格包含 outdbbandnum、filesize 和 filetimestamp。
SELECT
    rid,
    (foo.md).*
FROM (
    SELECT
        rid,
        ST_BandMetaData(rast, 1) AS md
    FROM dummy_rast
    WHERE rid=2
) As foo;
 rid | pixeltype | nodatavalue | isoutdb | path | outdbbandnum
-----+-----------+---- --------+---------+------+--------------
   2 | 8BUI      |           0 | f       |      |
                
      WITH foo AS (
    SELECT
        ST_AddBand(NULL::raster, '/home/pele/devel/geo/postgis-git/raster/test/regress/loader/Projected.tif', NULL::int[]) AS rast
)
SELECT
    *
FROM ST_BandMetadata(
    (SELECT rast FROM foo),
    ARRAY[1,3,2]::int[]
);
 bandnum | pixeltype | nodatavalue | isoutdb |                                      path                                      | outdbbandnum  | filesize | filetimestamp |
---------+-----------+-------------+---------+--------------------------------------------------------------------------------+---------------+----------+---------------+-
       1 | 8BUI      |             | t       | /home/pele/devel/geo/postgis-git/raster/test/regress/loader/Projected.tif      |            1  |    12345 |    1521807257 |
       3 | 8BUI      |             | t       | /home/pele/devel/geo/postgis-git/raster/test/regress/loader/Projected.tif      |            3  |    12345 |    1521807257 |
       2 | 8BUI      |             | t       | /home/pele/devel/geo/postgis-git/raster/test/regress/loader/Projected.tif      |            2  |    12345 |    1521807257 |