title: BigQuery cli bq how to use EXECUTE IMMEDIATE script
body: <p>I would like to use two SQL scripts to create and update a table in BigQuery using <code>bq query</code> command.
  Here are the two scripts :</p>
  <p>1- Creating the table</p>
  <pre class="lang-sql prettyprint-override"><code>EXECUTE IMMEDIATE 
      '''CREATE TABLE IF NOT EXISTS dataset.newtable (
          id STRING, ''' ||
          (SELECT STRING_AGG(
                  segment || 
                  &quot; INT64 &quot; ORDER BY segment
          ) FROM (
              SELECT DISTINCT segment FROM dataset.source
          )
      ) || 
      ''')''';
  </code></pre>
  <p>2- updating the table</p>
  <pre class="lang-sql prettyprint-override"><code>EXECUTE IMMEDIATE 
      '''INSERT dataset.newtable (
          SELECT id, ''' ||
          ( SELECT STRING_AGG(&quot;COUNTIF(
              segment = '&quot; ||
              segment ||
          &quot;') AS &quot; ||
          segment ORDER BY segment
      ) FROM (
          SELECT DISTINCT segment FROM dataset.source
      ) ) || 
      ''' FROM dataset.source GROUP BY 1 ORDER BY 1
  )''';
  </code></pre>
  <p>When using these two scripts as queries with the <code>bq query</code> command, I have got an error :</p>
  <pre><code>Syntax error: Expected keyword IMMEDIATE but got to end of the script at [1:8]
  </code></pre>
  <p>Is there any other way to do that?</p>
  <p>Thank you</p>