Skip to content

copyfrom in MySQL with sqlc does not recognize reserved keywords and does not escape column names manually or automatically #3984

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

Open
Umamad opened this issue Jun 8, 2025 · 1 comment

Comments

@Umamad
Copy link

Umamad commented Jun 8, 2025

Summary

Using :copyfrom in MySQL with sqlc and column names that are reserved keywords like create, read, update, delete fails with a MySQL syntax error, even if escaped.

Expected behavior

sqlc should either:

  • Automatically escape column names in the generated LOAD DATA LOCAL INFILE statement, or
  • Respect backticks in -- columns: directive

Actual behavior

The generated Go code produces a raw SQL string like:

LOAD DATA LOCAL INFILE 'Reader::xyz' INTO TABLE `role_system` (...) (role_id, system_id, create, read, update, delete)
@dosubot dosubot bot added the 📚 mysql label Jun 8, 2025
@Umamad
Copy link
Author

Umamad commented Jun 8, 2025

Work around

I made a work around using sed command
run this command after sqlc generate command.
this command works in bash
sed -i '' 's/(role_id, system_id, create, read, update, delete)/(`role_id`, `system_id`, `create`, `read`, `update`, `delete`)/g' data/repository/*.go

I also use make file and just add a command for it:

// Makefile
generate:
	sqlc generate
	sed -i '' 's/(role_id, system_id, create, read, update, delete)/(`role_id`, `system_id`, `create`, `read`, `update`, `delete`)/g' data/repository/*.go

GG

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

No branches or pull requests

1 participant