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
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.
It does not work on MySQL. My table and schema below:
schema:
CREATE TABLE pkg ( id text NOT NULL, vic VARCHAR(50) NOT NULL, kim text NOT NULL, order INTEGER NOT NULL,
PRIMARY KEY (id)
);
/* name: GetPkgID :many */
SELECT id,vic,kim FROM pkg WHERE vic = ANY($1::int[]) AND shop_id = ?;
sqlc generate
sql/query/pkg.sql:2:67: syntax error at or near "$"
sql/query/pkg.sql:2:76: syntax error at or near "]"
Activity
kyleconroy commentedon Dec 25, 2019
You're in luck! sqlc already supports this using
ANY. The following SQL:generate this method signature
Duplicate of #167
matheuscscp commentedon Dec 25, 2019
Sorry for not being specific enough: What about bulk inserts?
kyleconroy commentedon Dec 25, 2019
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.
However, this isn't really a true bulk insert. You can insert multiple records in a single query:
This approach can't support a dynamic number of records.
The suggested approach is to use COPY (see this excellent StackOverflow answer).
lib/pqhas special support for this use case. I've opened up #218 for the feature.BienTrinh commentedon Aug 30, 2020
It does not work on MySQL. My table and schema below:
schema:
CREATE TABLE
pkg(idtext NOT NULL,vicVARCHAR(50) NOT NULL,kimtext NOT NULL,orderINTEGER NOT NULL,PRIMARY KEY (
id));
/* name: GetPkgID :many */
SELECT
id,vic,kimFROMpkgWHEREvic= ANY($1::int[]) ANDshop_id= ?;sqlc generate
sql/query/pkg.sql:2:67: syntax error at or near "$"
sql/query/pkg.sql:2:76: syntax error at or near "]"
kyleconroy commentedon Aug 30, 2020
MySQL does not support arrays so it's not expected for this to work. I've opened #695 to track this issue.