Easier inserts with many columns #587
-
Suppose I have some table with a lot of columns, and we get bulk API requests with those fields specified. Right now, as far as I can tell, I'd need to have a query like: -- name: InsertThing :one
INSERT INTO members (a, lot, of, fields, that, this, type, of, data, has)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING *; This isn't the end of the world, but I'm wondering if it'd be possible to support something like: -- name: InsertThing :one
INSERT INTO members (a, lot, of, fields, that, this, type, of, data, has)
VALUES ($*)
RETURNING *; ? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
how about this?
and generating codes like: to updating optional fields, that is dynamic and type-safe. actually UPDATE, SELECT, INSERT, WHERE etc are same. ping: #580 |
Beta Was this translation helpful? Give feedback.
-
@landbed That might be getting a bit too magic. It's usually not the case that every column should be specified in an insert statement (e.g., an auto incrementing id), and I imagine sqlc wants to stay out of the business of guessing which columns are and aren't necessary in an insert statement. |
Beta Was this translation helpful? Give feedback.
-
You are correct that I'd like sqlc to avoid guessing which columns should be included and which ones shouldn't. When adding SQL enhancements, I like to add them as functions in the sqlc namespace. So maybe it should look like this? -- name: InsertThing :one
INSERT INTO members (a, lot, of, fields, that, this, type, of, data, has)
VALUES (sqlc.args())
RETURNING *; or -- name: InsertThing :one
INSERT INTO members (a, lot, of, fields, that, this, type, of, data, has)
VALUES sqlc.values()
RETURNING *; |
Beta Was this translation helpful? Give feedback.
-
Both of those LGTM! |
Beta Was this translation helpful? Give feedback.
You are correct that I'd like sqlc to avoid guessing which columns should be included and which ones shouldn't.
When adding SQL enhancements, I like to add them as functions in the sqlc namespace. So maybe it should look like this?
or