Skip to content

Raise compiler error for sql_header config with redirect to pre_hooks/query_options - #777

Merged
axellpadilla merged 1 commit into
dbt-msft:masterfrom
axellpadilla:guard/sql-header-not-supported
Jul 29, 2026
Merged

Raise compiler error for sql_header config with redirect to pre_hooks/query_options#777
axellpadilla merged 1 commit into
dbt-msft:masterfrom
axellpadilla:guard/sql-header-not-supported

Conversation

@axellpadilla

Copy link
Copy Markdown
Collaborator

Closes #562

``sql_headercannot work on SQL Server becauseCREATE VIEW` must be the first statement in a query batch — advisory SQL (SET, DECLARE) cannot precede it in the same `EXEC()` call. Every materialization path in the adapter routes model SQL through a temp view, so there's no way to inject a header into the same batch.

Instead of silently ignoring the config, this adds a guard in sqlserver__create_view_as (the single choke point for all materializations) that raises a compiler error:

sql_header is not supported on SQL Server.
CREATE VIEW must be the first statement in a batch, so sql_header cannot run in the same query.
Use pre_hooks for pre-model SQL or query_options for session-level SET options (e.g. query_options={'NOCOUNT': 'ON'}).

A functional test verifies the rejection for all four combinations (table/view × config/macro) in a single dbt run.

…y_options

SQL Server requires CREATE VIEW to be the first statement in a query batch,
so sql_header cannot run in the same query. Rather than silently ignoring the
config, raise a compiler error directing users to the appropriate alternatives.

Closes dbt-msft#562
@axellpadilla axellpadilla added this to the v1.12.0 milestone Jul 28, 2026
@axellpadilla
axellpadilla merged commit 8d1f433 into dbt-msft:master Jul 29, 2026
15 checks passed
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.

set_sql_header and config.sql_header don't do anything.

1 participant