You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
:copyfrom generates incorrect column name when inserting primary keys #2133
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:
Activity
Jille commentedon Apr 3, 2023
This happens because there is only a single column (not necessarily the primary key).
https://github.com/kyleconroy/sqlc/blob/d4902a6021731b34a63e386d1dbd7883f7d8314f/internal/codegen/golang/query.go#L117-L126
v.Nameis the Go name, not the DB name. The code just below (for multiple fields) usesf.DBNamecorrectly.codegen: Correctly generate CopyFrom columns for single-column copyfroms
twpayne commentedon Apr 3, 2023
Thank you very much for the fix :)