title: Subtransaction error when creating a materialized view with a plpgsql function
body: <p>I am scratching my head on this since a while. I am trying to create a materialized view and I want the query to be parallel. However when I use the following code :</p>
  <pre><code>CREATE MATERIALIZED VIEW xxx AS SELECT foo(myfield) FROM table
  </code></pre>
  <p>I got the following error :</p>
  <pre><code>cannot start subtransactions during a parallel operation
  CONTEXT:  PL/pgSQL function foo(text) line 1 during statement block entry
  </code></pre>
  <p>foo is a plpgsql function and as such considered as a subtransaction. However you can see there is nothing magic, I use it only to handle exceptions :</p>
  <pre><code>CREATE FUNCTION foo(TEXT) RETURNS NUMERIC LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE AS $$
      BEGIN RETURN CAST(REPLACE($1,',','.') AS NUMERIC);
      EXCEPTION
          WHEN invalid_text_representation THEN RETURN NULL;
      END; $$;
  </code></pre>
  <p>How can I create this view in a <strong>parallel way</strong> and still handle casting exceptions thanks to this plpgsql function ? Is there an other way to handle exceptions ? (try_catch from SQL server would be the fix here but sadly it's postgres).</p>
  <p>Thanks !</p>