title: Can I use a query parameter in a table name?
body: <p>I want to do something along the lines of:</p>
  
  <pre><code>SELECT some_things
  FROM `myproject.mydataset.mytable_@suffix`
  </code></pre>
  
  <p>But this doesn't work because the parameter isn't expanded inside the table name.</p>
  
  <p>This <em>does</em> work, using <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/wildcard-table-reference" rel="noreferrer">wildcard tables</a>:</p>
  
  <pre><code>SELECT some_things
  FROM `myproject.mydataset.mytable_*`
  WHERE _TABLE_SUFFIX = @suffix
  </code></pre>
  
  <p>However, it has some problems:</p>
  
  <ul>
  <li><p>If I mistype the parameter, this query silently returns zero rows, rather than yelling at me loudly.</p></li>
  <li><p>Query caching stops working when querying with a wildcard.</p></li>
  <li><p>If other tables exist with the <code>mytable_</code> prefix, they must have the same schema, even if they don't match the suffix. Otherwise, weird stuff happens. It seems like BigQuery either computes the union of all columns, or takes the schema of an arbitrary table; it's not documented and I didn't look at it in detail.</p></li>
  </ul>
  
  <p>Is there a better way to query a <em>single</em> table whose name depends on a query parameter?</p>