Determines whether a record is included in a random sample based on the provided properties and sample rate. Returns true with a probability equal to the sample_rate value.
Syntax
BOOLEAN ST_IsRandomSampled(RECORD tuple, INTEGER sample_rate)Parameters
| Parameter | Description |
|---|---|
tuple | The properties used to generate a hash value for the record. The hash value determines whether the record is sampled. Use ROW() to construct the tuple from one or more columns. For accurate sampling results, select properties or property combinations that are unique and evenly distributed. |
sample_rate | The percentage of records to sample, expressed as an integer. For example, a value of 50 samples 50% of records. |
Description
Returns
trueif the record is sampled; returnsfalseotherwise.The return value is calculated based on the values of
tupleandsample_rate.When applied to all records in a table, the
tuplevalue must be unique per record. This ensures the actual number of sampled records is as close as possible tosample_rate% of the total row count.
Examples
-- Return true for approximately half of the records, false for the other half.
SELECT ST_IsRandomSampled(ROW(id), 50) FROM table;
-- Calculate the area of geometries that fall in an 80% sample.
SELECT ST_Area(geom) FROM table WHERE ST_IsRandomSampled(ROW(geom), 80);
-- Sample half of the geometries and convert them to MVTGeom objects.
SELECT ST_AsMVTGeom(geom, ST_Transform(ST_TileEnvelope(0,0,0),4326)) FROM table
WHERE ST_IsRandomSampled(ROW(geom), 50) AND geom&&ST_Transform(ST_TileEnvelope(0,0,0),4326));