SAMPLE_POISSON()

All functions > BUSINESS > SAMPLE_POISSON()

Returns an integer drawn from a Poisson distribution with the given rate, based on the given hashing key.

Signatures

Returns: Deterministic non-negative integer from Poisson distribution

SAMPLE_POISSON(hashing_key: VARCHAR, rate: DOUBLE) → BIGINT
sql
ParameterTypeRequiredDescription
hashing_keyVARCHARYesString value to hash (typically user ID or session ID)
rateDOUBLEYesRate parameter λ, from 0 to 100. Also the mean and variance of the distribution.

Notes

  • Deterministic - same key always produces same value
  • Returns the smallest k with P(X <= k) > HASH01(key), the exact inverse CDF
  • Output is a non-negative integer (count of events), with no cap
  • Models event counts per interval (arrivals, defects, requests)
  • Common for demand forecasting, queue depth simulation
  • A NULL key or rate gives NULL; a rate of 0 gives 0
  • A rate below 0 or above 100 raises an error at runtime

Availability

StatusBackends
Not availablemysql

Examples

FeatureQL
RETURN
    -- Poisson draw with rate 5 for a fixed key
    f1 := SAMPLE_POISSON('k', 5e0),
    -- Poisson draw with rate 50 for the same key
    f2 := SAMPLE_POISSON('k', 50e0),
    -- A rate of 0 always gives 0
    f3 := SAMPLE_POISSON('k', 0e0),
    -- A NULL key gives NULL
    f4 := SAMPLE_POISSON(NULL::VARCHAR, 5e0)
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINT
5510NULL