Skip to content

Instantly share code, notes, and snippets.

@chrisgoddard
Created September 23, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisgoddard/18d19614714253d8e0646207a103616b to your computer and use it in GitHub Desktop.
Save chrisgoddard/18d19614714253d8e0646207a103616b to your computer and use it in GitHub Desktop.
BigQuery Custom UDFs
create or replace function dataset.array_int_least(x array<int64>) as
((select min(y) from unnest(x) as y));
create or replace function dataset.array_int_greatest(x array<int64>) as
((select max(y) from unnest(x) as y));
create or replace function dataset.array_timestamp_least(x array<timestamp>) as
((select min(y) from unnest(x) as y));
create or replace function dataset.array_timestamp_greatest(x array<timestamp>) as
((select max(y) from unnest(x) as y));
create or replace function dataset.array_date_least(x array<date>) as
((select min(y) from unnest(x) as y));
create or replace function dataset.array_date_greatest(x array<date>) as
((select max(y) from unnest(x) as y));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment