Skip to content

[proposal] Support LOAD DATA LOCAL INFILE for MySQL #2179

Description

@Jille

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.

Activity

  1. changed the title [-]Support LOAD DATA LOCAL INFILE for MySQL[/-] [+][proposal] Support LOAD DATA LOCAL INFILE for MySQL[/+] on Apr 4, 2023
  2. Jille commented on Apr 4, 2023

    @Jille
    ContributorAuthor

    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_package is the right place to put that. Passing go-sql-driver/mysql would behave mostly the same as passing database/sql, except that it allows :copyfrom support

  3. Jille commented on Apr 20, 2023

    @Jille
    ContributorAuthor

    I have two PRs ready for this, and a documentation branch I'll send later.

    #2220
    #2219
    Jille/sqlc@loaddata2...loaddata3

  4. Jille commented on Apr 25, 2023

    @Jille
    ContributorAuthor

    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

  5. SnoozeThis commented on Apr 25, 2023

    @SnoozeThis

    (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.

  6. added a commit that references this issue on Jun 25, 2023
  7. SnoozeThis commented on Nov 3, 2023

    @SnoozeThis

    An error occurred while snoozing: not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions