Add array_average function
See original GitHub issueWould be great if trino can add array_average and array_sum functions like in presto
array_average(array(double)) → double#
Returns the average of all non-null elements of the array. If there is no non-null elements, returns null.
array_sum(array(T)) → bigint/double#
Returns the sum of all non-null elements of the array. If there is no non-null elements, returns 0. The behavior is similar to aggregation function sum().
T must be coercible to double. Returns bigint if T is coercible to bigint. Otherwise, returns double.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Finding the average of an array using JS - Stack Overflow
You calculate an average by adding all the elements and then dividing by the number of elements. var ...
Read more >JavaScript How to Calculate Average of an Array
To find the average of an array in JavaScript, calculate the sum of the elements and divide the sum by the length of...
Read more >Javascript: Getting Average value of an Array - Flexiple
Simple approach to finding the average of an array ... We would first count the total number of elements in an array followed...
Read more >Program for average of an array (Iterative and Recursive)
Given an array, the task is to find average of that array. Average is the sum of array elements divided by the number...
Read more >C Program to Calculate Average Using Arrays - Programiz
In this C programming example, you will learn to calculate the average of n number of elements entered by the user using arrays....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From an end user perspective, it sill makes sense to add these functions similar to other database engines: It will be much easier to use and much readable and compact using array_average compared to subqueries or UNNEST.
One question i had in the PR is about rewriting those queries into some construct already supported (array_reduce/unnest/…) or a proper implementation.
@martint, @ebyhr : Can we make a decision, if we want to support this function? if yes how to support it by rewriting or by a proper implementation.
IMHO rewriting is better, but i would rather rewrite it to array_reduce then to unnest.
Let me change the title as there is another issue for
array_sum
in #4346