title: Postgres format string using array
body: <p>I'm looking for an easy way to format a string using an array, like so:</p>
  
  <pre><code>select format_using_array('Hello %s and %s', ARRAY['Jane', 'Joe']);
  
   format_using_array
  --------------------
  Hello Jane and Joe
  (1 row)
  </code></pre>
  
  <p>There's a format function but it needs explicit arguments and I don't know how many items are there in the array. I came up with a function like that:</p>
  
  <pre><code>CREATE FUNCTION format_using_array(fmt text, arr anyarray) RETURNS text
      LANGUAGE plpgsql
  AS $$
      declare 
          t text;
          length integer;
      begin
          length := array_length(arr, 1);
          t := fmt;
          for i in 1..length loop
             t := regexp_replace(t, '%s', arr[i]);
          end loop;
  
          return t;
      end
  $$;
  </code></pre>
  
  <p>But maybe there's an easier way that I don't know of, it's my first day using pgsql.</p>