-
Notifications
You must be signed in to change notification settings - Fork 931
Argument name for sqlc.arg() can't be SQL keyword #2837
-
Version
1.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 schema
create 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));
Configuration
version: "2" sql: - engine: "postgresql" schema: "schema.sql" queries: "queries.sql" gen: go: package: "models" sql_package: "pgx/v5" out: "models"
Playground URL
https://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.
All reactions
-
👍 2
user
is a reserved keyword in PostgreSQL. To get around this limitation, put user in single quotes.
-- name: StageUserData :copyfrom insert into "user_data" ("id", "user") values (sqlc.arg('id'), sqlc.arg('user'));
https://play.sqlc.dev/p/9fa2777d8a0f6df949672259c122da0687e266745c84d2450bc291a9c701135f
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 CopyFrom
statement instead of the proper column names.
For example, if I use sqlc.arg(user_)
it compiles fine, but the resulting code:
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 insert
statement defines the columns as id
and user
not id
and user_
.
☝️ this is a separate issue I will be filing here: #2833
Beta Was this translation helpful? Give feedback.
All reactions
-
user
is a reserved keyword in PostgreSQL. To get around this limitation, put user in single quotes.
-- 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.
All reactions
-
nice, i tried double quotes and didn’t think to try single.
Beta Was this translation helpful? Give feedback.