I think there would be lot of benefit for MADlib if such operators are in core. Questions like the one raised in the PR would be better answered by the Postgres community.
We have built generic functions with the same idea (see [1]). We define the following operations with arrays: function(array,array)->array (calls: General_2Array_to_Array) function(array,scalar)->array (calls: General_Array_to_Array) function(array,array)->scalar (calls: General_2Array_to_Element) function(array,scalar)->scalar (calls: General_Array_to_Element) function(array,scalar)->struct (calls: General_Array_to_Struct) We also define about 20 floating point element operations. Each element-wise array operation then boils down to just calling the specific General* function. [1] https://github.com/apache/incubator-madlib/blob/master/methods/array_ops/src/pg_gp/array_ops.c Best, Rahul On Fri, Feb 26, 2016 at 11:18 AM Jim Nasby <jim.na...@bluetreble.com> wrote: > Looking at [1] reminded me of something I've felt is missing from > Postgres arrays: the ability to perform arbitrary operations on arrays > on an element-by-element basis. You can sort-of simulate that with > unnest, but it's awkward and slow. > > Instead of functions for specific per-element operations (ie: > array_add()), would a more generic function (ie: array_op('+', array1, > array2)) benefit MADlib? I suspect the Postgres community would accept > such a function in core. > > [1] > > https://github.com/apache/incubator-madlib/pull/22/files#diff-ed598467a50f51272f2a5ad73c503a34L702 > -- > Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX > Experts in Analytics, Data Architecture and PostgreSQL > Data in Trouble? Get it in Treble! http://BlueTreble.com >