Skip to content

feat scripts: jinja2 in sql #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

danilshvalov
Copy link
Contributor

SQL queries often have duplicate elements, such as fields in SELECT. I would like to put such elements in a separate file to reduce duplication.

This Pull Request adds the ability to use Jinja2 substitution in SQL queries. The following is an example of usage.

_fields.sql
id,
first_name,
last_name
select_user_by_id.sql
SELECT
{% include '_fields.sql' %}
FROM users
WHERE id = $1
select_users.sql
SELECT
{% include '_fields.sql' %}
FROM users
ORDER BY id

Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant