Repository navigation
[proposal] Support LOAD DATA LOCAL INFILE for MySQL #2179
Description
Activity
- changed the title
[-]Support LOAD DATA LOCAL INFILE for MySQL[/-][+][proposal] Support LOAD DATA LOCAL INFILE for MySQL[/+]on Apr 4, 2023 Some more thoughts:
-
We need to encode the sqlc rows to TSV (or another CSV-like format) that is accepted by LOAD DATA INFILE. I propose to create an external library for that and let the generated code depend on it. (It felt like too much to generate inline.)
-
We need to configure sqlc which mysql driver is used, because database/sql doesn't natively support LOAD DATA INFILE. I think
sql_packageis the right place to put that. Passinggo-sql-driver/mysqlwould behave mostly the same as passingdatabase/sql, except that it allows:copyfromsupport
-
- added 2 commits that reference this issue
on Apr 20, 2023 I have two PRs ready for this, and a documentation branch I'll send later.
- added 7 commits that reference this issue
on Apr 21, 2023 - added a commit that references this issue
on Apr 21, 2023 - added 3 commits that reference this issue
on Apr 25, 2023 I need go-sql-driver/mysql to expose the *time.Location to encode correctly.
@SnoozeThis go-sql-driver/mysql#1416 || go-sql-driver/mysql#1419
(https://snoozeth.is/NFrLngXswx4) I will either wait until go-sql-driver/mysql#1416 is closed or until go-sql-driver/mysql#1419 is merged and then add a comment.
- added a commit that references this issue
on Jun 25, 2023 An error occurred while snoozing: not found
- added a commit that references this issue
on Oct 13, 2025
https://github.com/go-sql-driver/mysql#load-data-local-infile-support supports LOAD DATA LOCAL INFILE with an io.Reader.
We could implement the :copyfrom query annotation to use LOAD DATA LOCAL INFILE when using go-sql-driver. The generated code would call https://pkg.go.dev/github.com/go-sql-driver/mysql#RegisterReaderHandler with a new reader for this call (and deregister it afterwards).
I propose to keep the same :copyfrom name and semantics, even though that's technically incorrect for MySQL.
I've looked at the three MySQL drivers listed on https://github.com/golang/go/wiki/SQLDrivers and the other two don't seem to support LOAD DATA [LOCAL] INFILE, though they might support it in the future.
We'd probably want to add a setting where people can indicate which MySQL driver they're using so we can generate the code using the relevant package.