Skip to content

Using REPLACE instead of INSERT with :copyfrom in MySQL doesn't add REPLACE to resulting LOAD DATA LOCAL INFILE query #4339

@maglicheev-check24

Description

@maglicheev-check24

Version

1.30.0

What happened?

When using :copyfrom with MySQL, if original sql query is an INSERT one, resulting query string looks like

LOAD DATA LOCAL INFILE '%s' INTO TABLE locations %s (id, name, address, latitude, longitude)

However, when original query is a REPLACE one (so the operation is functionally an _up_sert), the resulting string is the exact same, when it, I believe, should be something like

LOAD DATA LOCAL INFILE '%s' REPLACE INTO TABLE locations %s (id, name, address, latitude, longitude)

Tested locally, the additional REPLACE seems to work

Relevant log output

Database schema

create table locations
(
    id   varchar(512) not null
        primary key,
    name            text         not null,
    address         text         not null,
    latitude        float        null,
    longitude       float        null
);

SQL queries

-- name: UpsertLocations :copyfrom
REPLACE INTO locations (id, name, address, latitude, longitude)
VALUES (?, ?, ?, ?, ?);

Configuration

version: "2"

sql:
  - engine: mysql
    schema: migrations
    queries: queries
    gen:
      go:
        package: models
        sql_package: "database/sql"
        sql_driver: "github.com/go-sql-driver/mysql"
        out: models

Playground URL

https://play.sqlc.dev/p/c26f675ffcf58bbe1a2165cab05ff94663e1e4d1f6ac67e0470b27a1df44eff6

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions