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

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 this issue Oct 26, 2024 · 2 comments
Labels
📚 mysql bug Something isn't working 💻 windows

Comments

@bignyap
Copy link

bignyap commented Oct 26, 2024

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 bignyap added the bug Something isn't working label Oct 26, 2024
@bignyap
Copy link
Author

bignyap commented Oct 26, 2024

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 pushed a commit to bignyap/go-gate-keeper that referenced this issue Oct 26, 2024
@bignyap
Copy link
Author

bignyap commented Oct 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql bug Something isn't working 💻 windows
Projects
None yet
Development

No branches or pull requests

2 participants
@bignyap and others