Skip to content

min_value

min_value(arr)

Description

Return min value of array (inspired from sql-snippets repo)

Examples

Call or Deploy min_value ?
Call min_value directly

The easiest way to use bigfunctions

  • min_value function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy min_value in your project

Why deploy?

  • You may prefer to deploy min_value in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

min_value function can be deployed with:

pip install bigfunctions
bigfun get min_value
bigfun deploy min_value
select bigfunctions.eu.min_value([1, 4, 3])
select bigfunctions.us.min_value([1, 4, 3])
select bigfunctions.europe_west1.min_value([1, 4, 3])
+-------+
| value |
+-------+
| 1     |
+-------+

Need help or Found a bug using min_value?
Get help using min_value

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about min_value

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.

Use cases

You have a table of products, and each product has an array of prices representing its price history. You want to find the lowest price ever recorded for each product.

WITH Products AS (
    SELECT
        'Product A' AS product_name,
        [10, 12, 8, 15, 9] AS prices
    UNION ALL
    SELECT
        'Product B' AS product_name,
        [20, 18, 18, 19, 21] AS prices
    UNION ALL
    SELECT
        'Product C' AS product_name,
        [5, 7, 5, 6, 4] AS prices
)
SELECT
    product_name,
    bigfunctions.us.min_value(prices) AS min_price
FROM Products;

This query would utilize the min_value function to efficiently determine the minimum value within the prices array for each product, effectively identifying the historical lowest price. You would replace bigfunctions.us with the appropriate dataset for your region.

Spread the word!

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on