Is there any way in Postgres to apply a function over a results of an array (or any sort of collection)?
For example if I have a function create function add1...
that increments a number by one, is there any way to do something like:
select map add1 array[1,5,8...];
and getting back
array [2,6,9...]
?
I am not sure if it has any sense over a select
as it can map a function on the single result directly:
select add1(x) from X;
Also, is there any concept of laziness here? All the functions will be 'strictly' applied?
Best Answer
If you are merely looking to increment each element of an input array, this simple function is one method of doing it.
Or queried from your table
Plain SQL version of the function: