As fans of dbt , we’re quite happy with the new Jinja2 template support for EXECUTE IMMEDIATE FROM !
This time our intern got the following assignement :
Create a sql script that using Jinja2 templating that does the following based on my input :
- Deployment Differentiation:
- Dynamically adapts to different deployment types (
prodand non-prod). - Uses distinct environment names (
prod1,prod2for production anddev,qa,stagingfor non-production).
- Dynamically adapts to different deployment types (
- Schema Creation:
- Creates specific schemas (
finance,sales,hrfor production anddevelopment,testing,supportfor non-production).
- Creates specific schemas (
- Database Setup:
- Creates databases named according to the environment (
{{ environment }}_db).
- Creates databases named according to the environment (
- Schema-Specific Table Creation:
- Creates multiple tables within each schema according to the environment (
{{ environment }}_{{schema}}_employeesfor example):orderstable with columnsid,item,quantity, andorder_date.customerstable with columnsid,name, andemail.productstable with columnsproduct_id,product_name, andprice.employeestable with columnsemployee_id,employee_name, andposition
- Creates multiple tables within each schema according to the environment (
- Production-Specific Setup:
- Creates a separate
prod_analytics_dbdatabase. - Within this database, creates an
analytics_reportstable with columnsreport_id,report_name, andcreated_date.
- Creates a separate
Professor Frosties input should be similar to the following :
EXECUTE IMMEDIATE FROM @setup_stage/setup_env_made_by_intern.sql
USING (DEPLOYMENT_TYPE => ‘prod’);



A bit tedious to debug because of going back and forth with uploading the file to the stage, but not that difficult overall. Very handy to have jinja templating for deployments!
This one took me longer than usual. Haven’t used jinja before and it was a fun learning experience! Thanks for keeping the interesting challenges coming