title: BIGQUERY An internal error occurred and the request could not be completed Error: 80038528
body: <p>I am trying to install a function. I don't understand what the problem is. I can install correctly when:</p>
  <ol>
  <li>I delete the pivot</li>
  <li>I use the Table and not the <code>unnest</code> only (so from the table, <code>unnest(a)</code>)</li>
  </ol>
  <pre><code>CREATE OR REPLACE FUNCTION `dataset.function_naming` (a ARRAY&lt;STRUCT&lt;ROW_ID STRING, KEY STRING, VALUE STRING&gt;&gt;, id_one STRING, id_two STRING, start_date DATE, end_date DATE) RETURNS INT64 
  AS (
      with tmp1 as (
              select ROW_ID,X,Y,Z,W
              from 
              (
                  select prop.ROW_ID,prop.KEY, prop.VALUE
                  from unnest(a) prop
              where prop.KEY in ('X','Y','Z','W')
              )
              
              PIVOT
                  (
                      MAX(VALUE) 
                      FOR  UPPER(KEY) in('X','Y','Z','W')
                  ) as PIVOT
          )
  
  select case when X is not null then 1,
              when Y is not null then 2,
              when Z is not null then 2,
              when W is not null then 2
         else 0
  from tmp1
  );
  
  </code></pre>
  <p>Thanks all.</p>