Argument name for sqlc.arg() can't be SQL keyword #2837
-
Version1.21.0 What happened?sqlc errors out complaining about arguments Relevant log output# package models
queries.sql:1:1: Invalid argument to sqlc.arg() Database schemacreate table "user_data" (
"id" varchar not null,
"user" varchar not null,
primary key ("id")
); SQL queries-- name: StageUserData: copyfrom
insert into "user_data" ("id", "user")
values (sqlc.arg(id), sqlc.arg(user)); Configurationversion: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "queries.sql"
gen:
go:
package: "models"
sql_package: "pgx/v5"
out: "models" Playground URLhttps://play.sqlc.dev/p/0dc89e4177151eca415a86676469f9cef991c373455641ddbacef05abab3f265 What operating system are you using?macOS What database engines are you using?PostgreSQL What type of code are you generating?Go |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I tried working around this by adding underscores to my parameter names, but the parameter names are used in the pgx For example, if I use func (q *Queries) StageUserData(ctx context.Context, arg []StageUserDataParams) (int64, error) {
return q.db.CopyFrom(ctx, []string{"user_data"}, []string{"id", "user_"}, &iteratorForStageUserData{rows: arg})
} is incorrect - the ☝️ this is a separate issue I will be filing here: #2833 |
Beta Was this translation helpful? Give feedback.
-
-- name: StageUserData :copyfrom
insert into "user_data" ("id", "user")
values (sqlc.arg('id'), sqlc.arg('user')); https://play.sqlc.dev/p/9fa2777d8a0f6df949672259c122da0687e266745c84d2450bc291a9c701135f |
Beta Was this translation helpful? Give feedback.
user
is a reserved keyword in PostgreSQL. To get around this limitation, put user in single quotes.https://play.sqlc.dev/p/9fa2777d8a0f6df949672259c122da0687e266745c84d2450bc291a9c701135f