The postgres function array_replace(anyarray, anyelement, anyelement) is useful when you need to replace one single element in the array.
But I need to replace a sequence of elements in the array with another sequence. I'd like to be able to have a function like this: array_replace(anyarray, anyarray, anyarray)
For example. If I have this array: [A, B, C, D, E, F]
I'd like to change it to [A, 1, 2, 3, D, E, F]
By calling a function like this: array_replace([A, B, C, D, E, F], [B, C], [1, 2, 3]);
The elements to be replaced should all be in the exact order in which are passed to the function, one following the other. So, the following call do not alter the original array, because B and C are not near elements of the original array:
array_replace([A, B, X, C, D, E, F], [B, C], [1, 2, 3]);
How do I create such a function ?