I am using PostgreSQL 9.6. I have an array like ARRAY['a', 'b']::text[] which comes from application code and is transformed a bit in SQL, so I do not know its length in an application code.
In a table I have a field of type jsonb which I need to set to a json object, where keys are values from the given array and the values are all the same and equal to current timestamp, i.e
| id | my_field |
---------------------------------------------------------
| 1 | {"a":"1544605046.21065", "b":"1544605046.21065"} |
I am trying to find an update query to perform this update, e.g. something like
UPDATE mytable
SET my_field = some_function(ARRAY['a','b']::text[], EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)
WHERE <some_condition>;
I was looking at jsonb_build_object function, which is likely to help me, if I could transform my array, interleaving its elements with current timestamp, however I did not find a way to do this.
Please note, that I am likely to have hundreds of thousands of records to update, therefore I am looking for a fast implementation.
I would be grateful for any advice on this matter.