min_frequency() and max_frequency()

Returns the minimum or maximum estimated frequencies of a value within a dataset.

  1. max_frequency (
  2. agg SpaceSavingAggregate,
  3. value AnyElement
  4. ) RETURNS DOUBLE PRECISION

min_frequency and max_frequency are accessors that operate on a frequency aggregate or a top N aggregate. Create a frequency or top N aggregate over the original dataset, then call min_frequency and max_frequency on the aggregate.

Required arguments

NameTypeDescription
aggSpaceSavingAggregateThe frequency or top N aggregate created over the original dataset
valueAnyElementThe value to find the frequency of

Returns

ColumnTypeDescription
min_freq or max_freqDOUBLE PRECISIONThe minimum or maximum estimated frequency for the value
note

When you create a frequency aggregate, you set a threshold frequency. Values that appear with lower-than-threshold frequency are not tracked. Calling min_frequency or max_frequency with such values returns a frequency of 0.

Sample usage

Find the minimum frequency of the value 3 in a column named value within the table value_test:

  1. SELECT toolkit_experimental.min_frequency(
  2. (SELECT toolkit_experimental.freq_agg(0.05, value) FROM value_test),
  3. 3
  4. );

Find the maximum frequency of the value foo in a column named value within the table value_test:

  1. SELECT toolkit_experimental.max_frequency(
  2. (SELECT toolkit_experimental.freq_agg(0.05, value) FROM value_test),
  3. 'foo'
  4. );