INSERT INTO logs (task_id, message) SELECT id as task_id, l as message FROM tasks, unnest(log) l ORDER BY task_id ASC;