Skip to content

Commit 9de5046

Browse files
authored
Merge pull request #11 from dbt-msft/rebrand-as-nested-with-statements
Rebrand as nested with statements
2 parents b755ec2 + 6ec49a2 commit 9de5046

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/nested_CTES.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ title: Nested CTES in TSQL, a treatise
33
sidebar_position: 6
44
---
55

6-
# Nested CTES in TSQL, a treatise
6+
# Nesting queries with WITH clauses in TSQL, a treatise
77

8-
## Ask
8+
## Background
9+
10+
### TL;DR
11+
12+
Allowing nested WITH statements (not in love with terminology, examples given below) would enable MSFT customers to fully take advantage of templating engines and their respective ecosystems. These templating engines are already very popular on non-MSFT database products.
913

1014
Today in TSQL, the below example is not correct TSQL, but the following two are.
1115

@@ -81,9 +85,9 @@ SELECT * FROM goku_outer
8185
IMHO, this is excessive and it makes query injection via templating needlessly difficult, especially given that both nested subqueries and sequentially nested CTEs are already supported.
8286

8387

84-
# Reasons (ordered by ease of explanation)
88+
## Reasons (ordered by ease of explanation)
8589

86-
## 1. Everyone else does it
90+
### 1. Everyone else does it
8791

8892
The open-source data engineering ecosystem is growing at a breakneck speed -- especially tools that work with cloud data warehouses (e.g. [Airflow](https://airflow.apache.org/), [dbt](https://www.getdbt.com/), [SQLFluff](https://www.sqlfluff.com/), and [Great Expectations](https://greatexpectations.io/))
8993

@@ -107,7 +111,7 @@ The below table shows which databases support this convention.
107111

108112

109113

110-
### Low-hanging, Syntactic Fruit
114+
### 2. Low-hanging, Syntactic Fruit
111115

112116
Both nested subqueries and sequentially nested CTEs are already supported, so IMO, it isn't a large amount of effor to support this.
113117

@@ -121,7 +125,7 @@ WITH goku_outer AS (
121125
SELECT * FROM goku_outer
122126
```
123127

124-
### more flexibility with SQL templating engines
128+
### 3. more flexibility with SQL templating engines
125129

126130
Quote from Jacob Matson ([@matsonj](https://github.com/matsonj)):
127131

@@ -166,4 +170,4 @@ In fact, the magic of dbt is just Jinja templating. dbt goes one step further an
166170

167171
If TSQL could allow wrapping arbitrary SELECT queries within a CTE, it would have the following effects on dbt custom adapter maintenance:
168172
- dbt-sqlserver and dbt-synapse get the benefits of [ephemeral](https://docs.getdbt.com/docs/building-a-dbt-project/building-models/materializations#ephemeral) materializations and dbt tests without extra work
169-
- dbt-msft users can take advantage of community-supported adapters with more confidence (many package maintainers make heavy use of CTE-query-wrapping)
173+
- dbt-msft users can take advantage of community-supported adapters with more confidence (many package maintainers make heavy use of CTE-query-wrapping)****

0 commit comments

Comments
 (0)