These are the docs for the Metabase master branch. Some features documented here may not yet be available in the current release. Check out the docs for the current stable version, Metabase v0.58.
Table variables

Table variables let you write a SQL query with a placeholder for the table name. When you run the query, Metabase substitutes the variable with the schema and table name.
Table variables are especially useful when combined with snippets, so you can write a generic query once and reuse it across different tables.
Adding a table variable to a query
Use double braces where you’d normally write a table name:
SELECT
COUNT(*)
FROM
{{table}}
You can use table variables anywhere a table name would go, including FROM and JOIN clauses:
SELECT
t.*,
p.title
FROM
{{table}} AS t
JOIN {{products_table}} AS p ON t.product_id = p.id
Metabase inserts the table reference using the schema-qualified name (e.g., public.orders), so some databases like PostgreSQL will require you to use an alias. For example: SELECT t.id FROM {{table}} t.
Setting the variable type to Table
After adding a {{variable}} to your query:
- Open the Variables sidebar (it should appear automatically).
- Change the variable type to Table.
- Under Table to map to, select a table from the picker (Required).
When you run the query, Metabase replaces the variable with the selected table’s schema and table name. To preview the code Metabase will run, click the eye icon.
Using table variables with snippets
One neat thing you can do is combine table variables with snippets. You can write a generic query as a snippet and reuse the snippet in multiple questions, each mapped to a different table.
For example, create a snippet called “row count” with:
SELECT
COUNT(*)
FROM
{{table}}
Then insert the snippet into different questions:
{{snippet: row count}}
In each question, open the Variables sidebar and map {{table}} to a different database table. This way, the same snippet can count rows in Products, Orders, or any other table.
Limitations
- Not available as dashboard filter parameters. You can’t connect a table variable to a dashboard filter widget. Table variables must be set directly on each question.
- SQL queries only. Table variables are available in native SQL queries, not in the query builder.
- No input widget. There’s no input widget for people to plug in a table. You must select the table to insert into the variable from the variables sidebar.
- Not supported in transforms. Table variables aren’t available in transforms yet.
Further reading
Read docs for other versions of Metabase.