Skip to content

fix(duckdb): report an annotated statement that cannot be converted - #4662

Open
xen0l wants to merge 1 commit into
sqlc-dev:mainfrom
xen0l:duckdb-dropped-statement
Open

xen0l wants to merge 1 commit into
sqlc-dev:mainfrom
xen0l:duckdb-dropped-statement

Conversation

@xen0l

@xen0l xen0l commented Oct 24, 2026

Copy link
Copy Markdown

Fixes #4656

Problem

The DuckDB parser skipped every statement that converted to ast.TODO. The span of a statement includes the comments before it, so the -- name: annotation was lost with the statement. sqlc generate exited 0, printed nothing, and generated no method for it.

Change

In internal/engine/duckdb/parse.go:

  • Keep skipping a statement that has no query annotation (INSTALL, LOAD and SET in a schema file).
  • Return an error for a statement that has one: query <name>: statement is not supported by the duckdb engine. The error points at the annotation line.
  • A malformed annotation on such a statement is reported with the annotation parser's own message. (No test covers this path.)

The parser now reads its input once (io.ReadAll) so that the statement offsets index the text.

Tests

New end-to-end cases (sqlc analyze --dialect duckdb):

  • analyze_unsupported_statement/duckdb: an annotated COPY after a valid query. Must fail, stderr.txt committed. It fails without the change (exit 0, JSON for one query) and passes with it.
  • analyze_skipped_schema_statements/duckdb: control. INSTALL, LOAD and SET in the schema file stay skipped. It passes with and without the change.

go test ./internal/endtoend -run TestReplay/base: 971 pass, 58 skip, 0 fail before; 973 pass, 58 skip, 0 fail after. The only difference is the two new cases.
go test ./internal/engine/... ./internal/core/... ./internal/compiler/... ./internal/codegen/... ./internal/cmd/... ./internal/metadata/... ./internal/sql/...: all ok.

Not run: the managed-db context, --tags=examples, and the internal/goldeneye checks.

Notes

The same check does not cover an unsupported expression inside a statement that converts (it is still typed as unknown). Changing that would alter how every unsupported expression is treated, so I left it.

The DuckDB parser skipped every statement that converted to ast.TODO. The
span of a statement includes the comments before it, so a "-- name:"
annotation was lost with the statement. sqlc generate exited 0, printed
nothing and generated no method for it.

Keep skipping a statement that has no query annotation (INSTALL, LOAD
and SET in a schema file). Return an error for a statement that has one,
and point it at the annotation.

Adds analyze_unsupported_statement and a control case,
analyze_skipped_schema_statements.
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.

duckdb: a named statement that the converter cannot handle is dropped without an error

1 participant