Closed
Description
Version
1.17.2
What happened?
I want to use :copyfrom
to insert primary key values. sqlc
generates an incorrect column name for the primary key field, breaking the query. I made a minimal example to reproduce this, which, when generating code to populate author.author_id
results in the error:
ERROR: column "authorID" does not exist (SQLSTATE 42703)
i.e. the author_id
column was incorrectly renamed to authorID
.
The specific incorrect code is at line 41 in the generated example/copyfrom.go
:
func (q *Queries) CreateAuthors(ctx context.Context, authorID []int32) (int64, error) {
return q.db.CopyFrom(ctx, []string{"authors"}, []string{"authorID"}, &iteratorForCreateAuthors{rows: authorID})
}
Here the incorrect column is visible in the third argument to q.db.CopyFrom
.
Relevant log output
No response
Database schema
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY
);
SQL queries
-- name: CreateAuthors :copyfrom
INSERT INTO authors (author_id) VALUES ($1);
Configuration
version: '2'
sql:
- schema:
- 'schema.sql'
queries:
- 'queries.sql'
engine: 'postgresql'
gen:
go:
out: 'example'
sql_package: 'pgx/v4'
Playground URL
https://play.sqlc.dev/p/e9e0f5f0257534acf1eb8864a3c36d3089b64f7c0b28f12264ae4494595dffb8
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go