Skip to content

Commit 0e2fe61

Browse files
authored
feat: Include preamble in CTE query construction (#1694)
1 parent b2e91dc commit 0e2fe61

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/commands/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,20 @@ export class VSCodeCommands implements Disposable {
10821082
return;
10831083
}
10841084

1085-
// Build the complete query
1086-
let query = "WITH ";
1085+
// Build the complete query including preamble before WITH clause
1086+
// Extract everything before the WITH clause (dbt configs, variables, etc.)
1087+
const preamble = text.substring(0, targetCte.withClauseStart).trim();
1088+
1089+
let query = "";
1090+
if (preamble) {
1091+
query += preamble + "\n\n";
1092+
this.dbtTerminal.debug(
1093+
"CteExecution",
1094+
`Including preamble (${preamble.length} chars) before WITH clause`,
1095+
);
1096+
}
1097+
1098+
query += "WITH ";
10871099
query += cteDefinitions.join(",\n");
10881100

10891101
// Add a simple SELECT to execute the target CTE with proper quoting

0 commit comments

Comments
 (0)