GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — duckdb: `sqlc.arg()`, `sqlc.narg()` and `@name` are not rewritten · Issue #4658 · sqlc-dev/sqlc Open DescriptionVersion
What happened?With I do not know if this is planned. #4621 describes named arguments only for engines that use Expected: the macros work like they do in the other engines. CauseThe preprocessor rewrites the sqlc macros before the engine parser runs ( Reproductionrepro4.sh#!/usr/bin/env bash rm -rf repro4 && mkdir repro4 && cd repro4 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 while IFS= read -r q; do printf -- '-- name: Q :many\n%s\n' "$q" > query.sql; rm -rf out echo "== $q"; sqlc generate 2>&1 | head -3; grep -hE '^func \(q \*Queries\) Q' out/query.sql.go 2>/dev/null done <<'EOF' SELECT id FROM items WHERE id = $1; SELECT id FROM items WHERE id = sqlc.arg(want_id); SELECT id FROM items WHERE id = sqlc.narg(want_id); SELECT id FROM items WHERE id = @want_id; SELECT id FROM items WHERE id IN (sqlc.slice(ids)); EOF Fix and notesI have a patch with end-to-end test cases, and I will open a pull request. Two notes on it:
Relevant log output== SELECT id FROM items WHERE id = $1; func (q *Queries) Q(ctx context.Context, id int32) ([]int32, error) { == SELECT id FROM items WHERE id = sqlc.arg(want_id); # package repro query.sql:1:1: where: unknown column "want_id" == SELECT id FROM items WHERE id = sqlc.narg(want_id); # package repro query.sql:1:1: where: unknown column "want_id" == SELECT id FROM items WHERE id = @want_id; # package repro query.sql:2:33: Parser Error: syntax error at or near "@" == SELECT id FROM items WHERE id IN (sqlc.slice(ids)); # package repro query.sql:1:1: where: unknown column "ids" Database schemaCREATE TABLE items (id INTEGER NOT NULL, name VARCHAR NOT NULL); SQL queriesSELECT id FROM items WHERE id = $1; SELECT id FROM items WHERE id = sqlc.arg(want_id); SELECT id FROM items WHERE id = sqlc.narg(want_id); SELECT id FROM items WHERE id = @want_id; SELECT id FROM items WHERE id IN (sqlc.slice(ids)); Configurationversion: "2" sql: - engine: "duckdb" schema: "schema.sql" queries: "query.sql" gen: go: package: "repro" out: "out" Playground URLNot 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 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 ActivityMetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |