sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.51k stars 810 forks source link

The copyform for MySQL throws "can't encode type float64 to TSV" when one of the column is of type float #3677

Open bignyap opened 3 weeks ago

bignyap commented 3 weeks ago

Version

1.25.0

What happened?

Copy or Load data should have gone without any error.

Relevant log output

can't encode type float64 to TSV

Database schema

CREATE TABLE tier_base_pricing (
  tier_base_pricing_id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
  base_cost_per_call float NOT NULL,
  base_rate_limit int,
  api_endpoint_id int NOT NULL,
  subscription_tier_id int NOT NULL
);

SQL queries

-- name: CreateTierPricings :copyfrom
INSERT INTO tier_base_pricing (subscription_tier_id, api_endpoint_id, base_cost_per_call, base_rate_limit) 
VALUES (?, ?, ?, ?);

Configuration

version: "2"
sql:
  - schema: "database/sqlc/schema"
    queries: "database/sqlc/queries"
    engine: "mysql"
    gen:
      go:
        out: "database/sqlcgen"
        sql_package: database/sql
        sql_driver: github.com/go-sql-driver/mysql
        emit_empty_slices: true

Playground URL

No response

What operating system are you using?

Windows

What database engines are you using?

MySQL

What type of code are you generating?

Go

bignyap commented 3 weeks ago

The error seems to be coming from https://github.com/hexon/mysqltsv/blob/2b86f827d04d8756e4837073ecf512595e49bc90/mysqltsv.go#L213C2-L213C9 . I do not see float is being handled anywhere.

bignyap commented 3 weeks ago

Adding the following line at (https://github.com/hexon/mysqltsv/blob/2b86f827d04d8756e4837073ecf512595e49bc90/mysqltsv.go#L213C2-L213C9)](https://github.com/hexon/mysqltsv/blob/2b86f827d04d8756e4837073ecf512595e49bc90/mysqltsv.go#L213C2-L213C9) fixes the issue for float64. We have to handle all the other variants of float.

case float64:
    return []byte(strconv.FormatFloat(v, 'f', -1, 64)), nil
Jille commented 3 weeks ago

/assign

Jille commented 3 weeks ago

Fixed with mysqltsv v0.2.2.

/close