Repository navigation
duckdb: a named statement that the converter cannot handle is dropped without an error #4656
Description
Version
main at commit 3ad8b20 (2026-10-23), built with CGO_ENABLED=0 go install github.com/sqlc-dev/sqlc/cmd/sqlc@3ad8b20fb02b5bea81591b673da0758b8685d951.
sqlc version prints v1.31.1 because internal/info/facts.go hard-codes it.
The DuckDB engine was added in #4621 and is not in a tagged release.
What happened?
A statement with a -- name: annotation that the DuckDB converter cannot convert is dropped.
sqlc generate exits with code 0 and prints nothing. It generates no method for the statement.
The other queries in the file are generated.
I saw this for COPY, EXPORT DATABASE, ATTACH, SET, PRAGMA, INSTALL and CALL.
The behavior is not consistent. A PIVOT in a FROM clause fails with unsupported FROM item *ast.TODO.
When the dropped statement is the only one in the file, the error is no queries contained in paths ....
That message does not name the statement.
A caller expects a method that does not exist, and the build breaks later. A reviewer sees a clean sqlc generate.
Expected: sqlc generate fails with an error that names the query.
Cause
internal/engine/duckdb/parse.go (lines 47–49 at this commit): a statement that converts to *ast.TODO is skipped
with continue. The span of a statement includes the comments before it, so the -- name: annotation is lost
with the statement.
Reproduction
repro2.sh
#!/usr/bin/env bash
rm -rf repro2 && mkdir repro2 && cd repro2
cat > sqlc.yaml <<'EOF'
version: "2"
sql:
- engine: "duckdb"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "repro"
out: "out"
EOF
cat > schema.sql <<'EOF'
CREATE TABLE items (id INTEGER NOT NULL, name VARCHAR NOT NULL);
EOF
methods() { if [ -f out/query.sql.go ]; then grep -c '^func (q \*Queries)' out/query.sql.go; else echo 0; fi; }
cat > query.sql <<'EOF'
-- name: ListItems :many
SELECT id, name FROM items;
-- name: ExportItems :exec
COPY (SELECT id, name FROM items) TO 'items.parquet' (FORMAT PARQUET);
EOF
sqlc generate; echo "sqlc exit code: $?"; echo "generated methods: $(methods)"
echo
while IFS= read -r stmt; do
printf -- '-- name: ListItems :many\nSELECT id, name FROM items;\n\n-- name: Other :exec\n%s\n' "$stmt" > query.sql
rm -rf out; sqlc generate >/dev/null 2>&1; rc=$?
printf '%-34s exit=%s methods=%s\n' "$stmt" "$rc" "$(methods)"
done <<'EOF'
EXPORT DATABASE 'export_dir';
ATTACH 'other.db' AS other;
SET threads = 2;
PRAGMA enable_progress_bar;
INSTALL spatial;
CALL pragma_version();
EOF
echo
printf -- "-- name: ExportItems :exec\nCOPY (SELECT id, name FROM items) TO 'items.parquet' (FORMAT PARQUET);\n" > query.sql
rm -rf out; sqlc generate; echo "sqlc exit code: $?"
echo
echo "== statements WITHOUT an annotation in the schema file are skipped, before and after"
printf 'INSTALL spatial;\nLOAD spatial;\nSET threads = 2;\nCREATE TABLE items (id INTEGER NOT NULL, name VARCHAR NOT NULL);\n' > schema.sql
printf -- '-- name: ListItems :many\nSELECT id, name FROM items;\n' > query.sql
rm -rf out; sqlc generate; echo "sqlc exit code: $?"; echo "generated methods: $(methods)"Fix
I have a patch with end-to-end test cases, and I will open a pull request.
Relevant log output
sqlc exit code: 0
generated methods: 1
EXPORT DATABASE 'export_dir'; exit=0 methods=1
ATTACH 'other.db' AS other; exit=0 methods=1
SET threads = 2; exit=0 methods=1
PRAGMA enable_progress_bar; exit=0 methods=1
INSTALL spatial; exit=0 methods=1
CALL pragma_version(); exit=0 methods=1
# package repro
error parsing queries: no queries contained in paths ./repro2/query.sql
sqlc exit code: 1
== statements WITHOUT an annotation in the schema file are skipped, before and after
sqlc exit code: 0
generated methods: 1Database schema
CREATE TABLE items (id INTEGER NOT NULL, name VARCHAR NOT NULL);SQL queries
-- name: ListItems :many
SELECT id, name FROM items;
-- name: ExportItems :exec
COPY (SELECT id, name FROM items) TO 'items.parquet' (FORMAT PARQUET);Configuration
version: "2"
sql:
- engine: "duckdb"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "repro"
out: "out"Playground URL
Not available. play.sqlc.dev runs only v1.18.0–v1.25.0, and the DuckDB engine is not in a release (v1.25.0 answers unknown engine: duckdb; main, a commit and every later release return HTTP 500). The report has a script that needs only go install github.com/sqlc-dev/sqlc/cmd/sqlc@3ad8b20fb02b5bea81591b673da0758b8685d951.
What operating system are you using?
Linux
What database engines are you using?
(none of the listed options; the engine is duckdb)
What type of code are you generating?
Go
Activity