I would like to create a function that given a value of any type, a dimension of the unidimensional array and the column to set, will return a unidimensional array that has all values null except for the value at the given column that would be set to the value given.
The questions are: is it possible to have the function return a variable type result ?
is it possible to create a variable type temporary variable ? The code bellow is what I created tentatively to do it but it does not work.
create function arraycol(v anyelement,n int,i int) returns anyarray language plpgsql as $$
declare r anyarray;
begin
r=array_fill(null,array[n]);
r[i]=v;
return r;
end $$;