title: Adding a value at specific index in Postgresql
body: <p>I need to assign the result of a function to an array like I used to do using Oracle:</p>
  
  <pre><code>DECLARE
    array array_t := array_t(); -- Initialise it
    v_idx NUMBER:=0;
  
  BEGIN
      v_idx:= v_idx+1;
      array.extend;
      array(v_idx):= regexp_replace(
                    'HELLO WORLD', '(^|[^a-z0-9])' || 'HELLO' || '($|[^a-z0-9])', 
                    '\1' || 'GOOD BYE' || '\2', 1, 0,  'i');
      DBMS_OUTPUT.PUT_LINE('array(v_idx): '||array(v_idx)||' ,v_idx: '||v_idx);
  
  END;
  /
  </code></pre>
  
  <p>In PostgreSQL, I have tried this without successful results:</p>
  
  <pre><code>DECLARE
    x_array VARCHAR[];
    idx INTEGER:=1;
  
  BEGIN 
    x_array[idx]:=string_to_array(SELECT REGEXP_REPLACE('HELLO WORLD','(^|[^a-z0-9])' || 'HELLO' || '($|[^a-z0-9])','\1' || 'GOOD BYE' || '\2','g')))
    RAISE NOTICE 'x_array:% ', x_array;
  END;
  /
  </code></pre>
  
  <p>How can you handle to store strings in an array and store/retrieve using index value? Should I use other object to be able to get/put elements by index?</p>
  
  <p>Thanks a lot</p>