If you’ve ever seen {{ }} inside SQL and thought ‘what is this?’ — you just met Jinja
What is Jinja Template? (Explained in the Simplest Way)
If you’ve ever seen {{ }} inside SQL and thought ‘what is this?’ — you just met Jinja

What is Jinja Template? (Explained in the Simplest Way)
If you’re learning tools like dbt, Flask, or even some Python-based frameworks, you might have seen something like this:
{{ variable_name }}
or
{% for item in list %}
And the first thought most beginners have is:
“Why is my SQL suddenly looking like code?”
If you felt confused, don’t worry — you’re not alone.
Let’s simplify Jinja in the easiest way possible.
What is Jinja?
Jinja is a templating language.
In simple words:
Jinja helps you generate code dynamically instead of writing the same thing again and again.
It allows you to use:
- variables
- loops
- conditions (if/else)
inside your SQL or text files.
Why Do We Need Jinja?
Imagine you have to write SQL like this:
SELECT FROM sales_2022 UNION ALL SELECT FROM sales_2023 UNION ALL SELECT * FROM sales_2024
This works fine for 3 tables.
But what if you have 20 tables?
Writing repetitive SQL becomes boring, messy, and error-prone.
That’s where Jinja becomes extremely useful.
Jinja Makes Your Code Reusable
Instead of repeating SQL manually, you can do something like this:
{% for year in [2022, 2023, 2024] %} SELECT * FROM sales_{{ year }} {% if not loop.last %} UNION ALL {% endif %} {% endfor %}
Now Jinja automatically generates the SQL for all years.
So instead of writing 20 queries, you write one smart template.
Where is Jinja Used?
Jinja is commonly used in:
- dbt (very important in data engineering)
- Flask (Python web development)
- automation scripts
- dynamic SQL generation
In dbt, Jinja is used to:
- build reusable transformations
- create dynamic models
- use variables like
ref() - write loops for repeated logic
- simplify complex SQL workflows
That’s why if you’re learning dbt, Jinja becomes unavoidable.
Why Jinja Feels Confusing at First (And That’s Normal)
If you come from a Computer Science background, you may already know what templating is.
But if you’re learning data engineering tools like dbt, Jinja suddenly appears out of nowhere and it feels like:
“Wait… why is my SQL acting like Python?”
And honestly, that’s exactly how I felt too.
In today’s tech world, there are so many tools and concepts that appear everywhere:
- Git
- Docker
- dbt
- Jinja
- cloud
- pipelines
Sometimes it feels like everyone else already knows these things…
and you’re the only one trying to catch up.
But the truth is:
Most people are learning on the go.
That’s why I’m writing these posts — to break down concepts in a simple way, so nobody feels lost in this fast-moving era.
The Simplest Way to Understand Jinja
Here’s the best mental model:
Jinja is like a smart text generator.
You write a template…
and Jinja fills in the missing values for you.
So instead of writing the same code again and again, you write it once and let Jinja generate the rest.
One-Line Definition
Jinja is a templating tool that helps you write dynamic and reusable code using variables, loops, and logic.
Final Thought
Jinja might look confusing at first…
but once you understand why it exists, you’ll realize:
It saves time, reduces repetition, and makes your code cleaner.
And if you’re learning dbt, understanding Jinja is one of the best skills you can build early.
Closing Line
If you’re learning data engineering and dbt, follow along — as I learn, we learn.
메타데이터
- post_id
- b7b5a06802b3
- slug
- if-youve-ever-seen-inside-sql-and-thought-what-is-this-you-just-met-jinja-b7b5a06802b3
- url
- https://medium.com/@uvs.hema/if-youve-ever-seen-inside-sql-and-thought-what-is-this-you-just-met-jinja-b7b5a06802b3
- canonical_url
- https://medium.com/@uvs.hema/if-youve-ever-seen-inside-sql-and-thought-what-is-this-you-just-met-jinja-b7b5a06802b3
- author_url
- https://medium.com/@uvs.hema
- status
- ok
- fetched_at
- 2026-06-24 13:29:15