Skip to content
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

sqlite: bulk insert / copyfrom equivalent #3305

Open
wilsonehusin opened this issue Mar 31, 2024 · 5 comments
Open

sqlite: bulk insert / copyfrom equivalent #3305

wilsonehusin opened this issue Mar 31, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@wilsonehusin
Copy link

wilsonehusin commented Mar 31, 2024

What do you want to change?

SQLite 3.7.11 and above supports bulk inserts with the syntax:

INSERT INTO 'tablename' ('column1', 'column2') VALUES
  ('1data1', '1data2'),
  ('2data1', '2data2'),
  ...
  ('Ndata1', 'Ndata2');

How difficult would it be to support this in sqlc? Happy to contribute if that's what's required to make it happen!

What database engines need to be changed?

SQLite

What programming language backends need to be changed?

No response

@wilsonehusin wilsonehusin added enhancement New feature or request triage New issues that hasn't been reviewed labels Mar 31, 2024
@msbatarce
Copy link

That type of multiple inserts is supported by most engines, but, at the moment, not suported by sqlc which would by nice IMO. That being said, it isnt really a robust bulk instert like COPY on postgres or LOAD DATA and shouldn't use :copyfrom. The thing is that multiple inserts with VALUES has a limit on how many rows can be instered at one time (somewhere I read that it was 500 rows for sqllite, nbut not sure).

@rishi-kulkarni
Copy link

rishi-kulkarni commented Apr 1, 2024

If you want to get really cute about it, you can already use json_each on a single parameter:

INSERT INTO users(name, email) SELECT e.value ->> 'name', e.value ->> 'email' FROM json_each(?) e

EDIT: Forgot the .value bits.

@mondy
Copy link

mondy commented Apr 15, 2024

I too need this feature.
I want to bulk insert a BLOB value.
Inserting BLOB values using json is a circuitous process.

@Arthur-Sk
Copy link

Any update on this?

@brandur
Copy link

brandur commented Jul 10, 2024

@rishi-kulkarni OOC, does your example above work for you? I'm basically looking for any workaround to get a multi-value into SQLite, but when I plug that into sqlc, it doesn't seem to respect a parameter to json_each:

-- name: JSONEachTest :execresult
INSERT INTO users(name, email) SELECT e.value ->> 'name', e.value ->> 'email' FROM json_each(?) e;
const jSONEachTest = `-- name: JSONEachTest :execresult
INSERT INTO users(name, email) SELECT e.value ->> 'name', e.value ->> 'email' FROM json_each(?) e
`

func (q *Queries) JSONEachTest(ctx context.Context, db DBTX) (sql.Result, error) {
	return db.ExecContext(ctx, jSONEachTest)
}

(Note, no parameters extracted to JSONEachTest.)

@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants