All Products
Search
Document Center

PolarDB:ST_NumMaterials

Last Updated:Mar 28, 2026

Returns the number of materials in an sfmesh object.

Syntax

int4 ST_NumMaterials(sfmesh sfmeshObject);

Parameters

ParameterDescription
sfmeshObjectThe sfmesh object to query.

Description

ST_NumMaterials counts the entries in the materials array of an sfmesh object and returns the count as an integer.

Example

The following example queries an sfmesh object that has one material entry. The sfmesh object is constructed inline using a JSON literal cast to the sfmesh type.

SELECT ST_NumMaterials('{
  "meshgeoms": ["MESHGEOM(PATCH(TRIANGLESTRIP(0 0,0 10,10 10,10 0)))"],
  "materials": [{"type": "db", "attributes": {"schema": "public", "table": "t_material", "column": "the_material", "key": "num=1"}}],
  "primitives": [{"meshgeom": 0, "material": 0}],
  "nodes": [{"primitive": 0}]
}'::sfmesh);

-- Result: 1 (the materials array contains one entry)