sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.

Home Page:https://www.sqlfluff.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle mix of jinja and placeholder SQL?

notatallshaw-gts opened this issue · comments

Search before asking

  • I searched the issues and found no similar issues.

Description

I would like to be able to format and lint SQL that has two different templating styles, namely jinja and colon based placeholders.

Maybe there is already a way to support this, but searching through the docs, google, and issues here I can't find anything.

Use case

We largely use placeholder colon style syntax for our SQL templating, e.g.

SELECT foo
FROM schema.table
WHERE value = :value

But there are cases where we run queries against a matrix of schema and table names from Apache Airflow, so our SQL instead looks like:

SELECT foo
FROM {{ params.schema_name }}.{{ params.table_name }}
WHERE value = :value

The Jinja templating is applied by Airflow first, and then the sql driver/library (or in fact SqlAlchemy in our case) applies the placeholder templating.

I thought this would have been a very common use case, but judging by the fact I can't find another reported issue I guess it's fairly niche.

Dialect

N/A

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Just ran into this myself, but with Jinja + numeric placeholders (eg. :1) in Snowflake. Wondering if there is a work around for the time being?