-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does this work for bulk operations? #216
Comments
Sorry for not being specific enough: What about bulk inserts? |
There are a few ways to do bulk inserts in Go. This article from 2017 goes into two approaches. The first approach, insering multiple records inside a transaction, can be used today with sqlc. -- name: InsertBook :exec
INSERT INTO books (key, title) VALUES ($1, $2) However, this isn't really a true bulk insert. You can insert multiple records in a single query: -- name: BulkInsert :exec
INSERT INTO books (key, title) VALUES
($1, $2),
($3, $4),
($5, $6) This approach can't support a dynamic number of records. The suggested approach is to use COPY (see this excellent StackOverflow answer). |
It does not work on MySQL. My table and schema below: sqlc generate |
MySQL does not support arrays so it's not expected for this to work. I've opened #695 to track this issue. |
Imagine my program receives a list of Book unique keys, and it needs to return the list of these Books. The query would be something like this:
How would I use sqlc for that?
The text was updated successfully, but these errors were encountered: