The Template Parameters feature enables the assignment of a set of parameters as JSON and making them available in SQL Lab using the Jinja Framework.
In the example below, a virtual dataset based on a movies database named Pagila is used. Then selecting the ellipsis icon, click on the sub-menu item Parameters.
SELECT
CONCAT({{customer_alias}}.last_name, ', ', {{customer_alias}}.first_name) AS customer,
{{address_alias}}.phone,
{{film_alias}}.title
FROM
{{rental_alias}}
INNER JOIN {{customer_alias}} ON {{rental_alias}}.customer_id = {{customer_alias}}.customer_id
INNER JOIN {{address_alias}} ON {{customer_alias}}.address_id = {{address_alias}}.address_id
INNER JOIN {{inventory_alias}} ON {{rental_alias}}.inventory_id = {{inventory_alias}}.inventory_id
INNER JOIN {{film_alias}} ON {{inventory_alias}}.film_id = {{film_alias}}.film_id
WHERE
{{rental_alias}}.return_date IS NULL
AND rental_date < CURRENT_DATE
ORDER BY
title
LIMIT 5;
The Template Parameters panel will appear. In this panel, you can define JSON parameters to represent all the {{ }} encapsulated references above, as shown in the example below:
{
"rental_alias": "rental",
"customer_alias": "customer",
"address_alias": "address",
"inventory_alias": "inventory",
"film_alias": "film"
}
.png)
After applying the above and executing the query, you will get the respective results being returned which also verifies that the template parameters are working correctly.
.png)