Closed
Description
Version
1.13.0
What happened?
I have a query that is using solely named parameters (sqlc.arg(...)
), and sqlc generate
fails with that. I expected the query to successfully generate Go code. If there's at least 1 $1
-type parameter, the query works. See this working playground link.
I forked the repo to verify that it's not just failing for my queries. See CreateBooks
query below.
Really appreciate the batch feature, it's simplified so much code. 👏
Relevant log output
in sqlc/examples/batch
❯ ~/bin/sqlc-dev generate
# package batch
postgresql/query.sql:18:1: :batch* commands require parameters
Database schema
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY,
name text NOT NULL DEFAULT ''
);
CREATE TYPE book_type AS ENUM (
'FICTION',
'NONFICTION'
);
CREATE TABLE books (
book_id SERIAL PRIMARY KEY,
author_id integer NOT NULL REFERENCES authors(author_id),
isbn text NOT NULL DEFAULT '' UNIQUE,
book_type book_type NOT NULL DEFAULT 'FICTION',
title text NOT NULL DEFAULT '',
year integer NOT NULL DEFAULT 2000,
available timestamp with time zone NOT NULL DEFAULT 'NOW()',
tags varchar[] NOT NULL DEFAULT '{}'
);
SQL queries
-- name: CreateBook :batchone
INSERT INTO books (
author_id,
isbn,
book_type,
title,
year,
available,
tags
) VALUES (
sqlc.arg(named_author),
sqlc.arg(named_isbn),
sqlc.arg(named_book_type),
sqlc.arg(named_title),
sqlc.arg(named_year),
sqlc.arg(named_available),
sqlc.arg(named_tags)
)
RETURNING *;
Configuration
{
"version": "1",
"packages": [
{
"path": "postgresql",
"name": "batch",
"schema": "postgresql/schema.sql",
"queries": "postgresql/query.sql",
"engine": "postgresql",
"sql_package": "pgx/v4",
"emit_json_tags": true,
"emit_prepared_queries": true,
"emit_interface": true
}
]
}
Playground URL
https://play.sqlc.dev/p/e6e9a855ee1820332afeb30221961e3c7ed501fdaa73450e6684d3c63e40002b
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go