Skip to content

fix: render SQL Server functions, schemas, merges and sources the engine accepts, and list warehouse Recall relations portably - #1351

Closed
kvlonge wants to merge 4 commits into
mainfrom
fix/clickhouse-recall-sqlserver-tvf
Closed

kvlonge wants to merge 4 commits into
mainfrom
fix/clickhouse-recall-sqlserver-tvf

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Why

Native parser work found SQL that SQLBuild renders but the warehouse rejects:

  • SQL Server table functions rendered as scalar ones (BEGIN RETURN (<select list>) END); an inline TVF must be RETURNS TABLE AS RETURN (<query>).
  • A SQL Server schema name with ' broke the EXEC('CREATE SCHEMA …') string.
  • SQL Server requires ; after MERGE; render_merge omitted it (no caller uses it on SQL Server yet).
  • A source expression starting with WITH was wrapped as a derived table, which SQL Server cannot parse.
  • sqb recall schema --backend warehouse used LIKE … ESCAPE '\', which ClickHouse cannot parse.

Changes

  • SQL Server: a TABLE return renders RETURNS TABLE AS RETURN (<query>), keeping SELECT and @name arguments; scalars unchanged.
  • SQL Server: the schema identifier's quotes are doubled inside EXEC; MERGE ends with ;.
  • SQL Server: a WITH source expression fails early with A715 and a rewrite hint instead of a warehouse syntax error. Relation names such as with_orders are unaffected.
  • Recall: state relations are matched with SUBSTRING(table_name, 1, 10) = '_sqlbuild_', which needs no escape syntax.

Verification

  • SQL Server unit cases for each rendering, with expected SQL matching statements the lane checked on SQL Server 2022 under PARSEONLY.
  • Recall integration case: warehouse schema lists _sqlbuild_fingerprints and not project tables.
  • SQL Server adapter unit tests and Recall CLI tests (65) and make check-ci pass locally. No SQL Server or ClickHouse warehouse runs here; CI covers the rest.

DuckShop: not applicable; DuckShop runs on DuckDB, which does not use these SQL Server or ClickHouse renderings.

…use Recall relations portably

SQL Server's render_create_function stripped a table function's SELECT and
wrapped it in BEGIN RETURN (...) END, which the engine rejects. A TABLE return
now renders RETURNS TABLE AS RETURN (<query>).

sqb recall schema --backend warehouse matched state relations with
LIKE '\_sqlbuild\_%' ESCAPE '\', which ClickHouse cannot parse. A prefix
comparison with SUBSTRING needs no escape in any dialect.
…n and refuse WITH source expressions

render_create_schema doubled quotes only in the sys.schemas lookup, so a schema
name with a quote broke the EXEC string. render_merge now ends with the
semicolon SQL Server requires. A source expression starting with WITH cannot
sit in a derived table on SQL Server, so it now fails with A715 and a rewrite
hint instead of a warehouse syntax error.
@kvlonge
kvlonge enabled auto-merge (squash) November 7, 2026 23:25

kvlonge commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Folded into the single combined sqlbuild PR (D625/D626), which the SQLBuild lane is assembling now and opens once #1377 lands. Branch kept.

@kvlonge kvlonge closed this Nov 8, 2026
auto-merge was automatically disabled November 8, 2026 21:16

Pull request was closed

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