Assuming I have two array fields in a table, like this:
Column | Type |
--------+-----------+
index | integer[] |
value | integer[] |
Where both index and value are equal in length, and the values in 'index' are guaranteed to be unique, for example:
SELECT * FROM ArrayTest;
index | value
-----------+-----------------------------------
{1,3,5,6} | {100, 103, 105, 106}
How would I make a query which returns a new array, where the values in 'index' are used as array indexes, and the values in 'value' become the values associated with the given index, i.e. something like:
SELECT some_array_function(index, value) as newarray;
new_array
--------------------------------
{100, NULL, 103, NULL, 105, 106}
What I want to achieve is the same as array_combine in PHP.
array_combineonly when the indexes are integers)