Title: MySQL Parameter Binding Issue with sqlc Python Plugin · Issue #90 · sqlc-dev/sqlc-gen-python · GitHub
Open Graph Title: MySQL Parameter Binding Issue with sqlc Python Plugin · Issue #90 · sqlc-dev/sqlc-gen-python
X Title: MySQL Parameter Binding Issue with sqlc Python Plugin · Issue #90 · sqlc-dev/sqlc-gen-python
Description: Getting MySQL syntax error when trying to register users - Parameter binding issue What I'm trying to do I'm building a FastAPI application with MySQL and using sqlc to generate my database repository code. Every time I try to register a...
Open Graph Description: Getting MySQL syntax error when trying to register users - Parameter binding issue What I'm trying to do I'm building a FastAPI application with MySQL and using sqlc to generate my database reposit...
X Description: Getting MySQL syntax error when trying to register users - Parameter binding issue What I'm trying to do I'm building a FastAPI application with MySQL and using sqlc to generate my database...
Opengraph URL: https://github.com/sqlc-dev/sqlc-gen-python/issues/90
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MySQL Parameter Binding Issue with sqlc Python Plugin","articleBody":"# Getting MySQL syntax error when trying to register users - Parameter binding issue\n\n## What I'm trying to do\nI'm building a FastAPI application with MySQL and using sqlc to generate my database repository code. Every time I try to register a user through my `/register` endpoint, I get a MySQL syntax error about the `?` placeholders.\n\n## The Problem\nWhenever I call my user registration endpoint, my application crashes with this error. It seems like the generated sqlc code isn't working properly with MySQL parameter binding.\n\n## Environment\n- **sqlc version**: 1.27.0\n- **Plugin**: sqlc-gen-python_1.3.0.wasm\n- **Database**: MySQL 8.0+\n- **Python**: 3.10\n- **SQLAlchemy**: 2.x\n- **MySQL Driver**: mysql-connector-python (also tested with PyMySQL)\n\n## Configuration\n```yaml\nversion: \"2\"\nplugins:\n - name: py\n wasm:\n url: https://downloads.sqlc.dev/plugin/sqlc-gen-python_1.3.0.wasm\n sha256: fbedae96b5ecae2380a70fb5b925fd4bff58a6cfb1f3140375d098fbab7b3a3c\nsql:\n - engine: mysql\n schema: \"database/migrations\"\n queries: \"database/queries\"\n codegen:\n - out: repository\n plugin: py\n options:\n package: repository\n emit_sync_querier: true\n emit_async_querier: true\n```\n\n## SQL Query\n```sql\n-- name: InsertUser :execresult\nINSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?);\n```\n\n## Generated Code (Problematic)\n```python\nINSERT_USER = \"\"\"-- name: insert_user \\\\:execresult\nINSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?)\n\"\"\"\n\ndef insert_user(self, *, firstname: Any, lastname: Any, email: Any, password: Any) -\u003e sqlalchemy.engine.Result:\n return self._conn.execute(sqlalchemy.text(INSERT_USER), {\n \"p1\": firstname,\n \"p2\": lastname,\n \"p3\": email,\n \"p4\": password,\n })\n```\n\n## Error\n```\nmysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?, ?)' at line 2\n\nsqlalchemy.exc.ProgrammingError: (mysql.connector.errors.ProgrammingError) 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?, ?)' at line 2\n[SQL: -- name: insert_user :execresult\nINSERT INTO users (firstname, lastname, email, password) VALUES (?, ?, ?, ?)\n]\n```\n\n## What I Think is Happening\nFrom my debugging, it looks like sqlc generates SQL with `?` placeholders but then the Python code tries to pass parameters as a dictionary like `{\"p1\": firstname, \"p2\": lastname}`. From what I can tell, MySQL with SQLAlchemy doesn't like this combination.\n\n## What I Expected\nI expected the generated code to just work out of the box with MySQL, like it probably does with PostgreSQL.\n\n## What I've Tried\n1. Switching from `mysql-connector-python` to `PyMySQL` - same error\n2. Looking at the generated code and trying to understand why it's not working\n3. Manually editing the generated code (but this gets overwritten when I run `sqlc generate` again)\n\n## Impact on Me\nThis is pretty frustrating because:\n- I can't use sqlc with MySQL without manually fixing the generated code every time\n- I have to either:\n - Manually edit the generated files after every `sqlc generate` (not sustainable)\n - Create wrapper classes to fix the parameter binding (extra work)\n - Switch to a different tool (defeats the purpose of using sqlc)\n\n## Is this a known issue?\nI'm not sure if this is a bug or if I'm doing something wrong with my configuration. Any help would be appreciated!\n\n## Possible Solutions (from my research)\nMaybe the generated code could:\n1. Use positional parameters: `[firstname, lastname, email, password]` instead of the dictionary\n2. Or generate SQL with `:p1, :p2, :p3, :p4` instead of `?, ?, ?, ?`\n3. Or add a config option to choose the parameter style for different databases\n","author":{"url":"https://github.com/santinalbrowns","@type":"Person","name":"santinalbrowns"},"datePublished":"2025-08-14T09:05:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/90/sqlc-gen-python/issues/90"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:67faff8d-eaf9-df30-473d-c9f9ed2fb00b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B296:374D34:35095C5:462BA0B:696DC4DE |
| html-safe-nonce | db2c2151c88858fccb04a48919663616b99165573f01a709b4c09235e4f68d7e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjk2OjM3NEQzNDozNTA5NUM1OjQ2MkJBMEI6Njk2REM0REUiLCJ2aXNpdG9yX2lkIjoiMTk0NjA4Njk5ODI2MjI2OTE1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 16fbb3547fd6dca42975d275cdcdb3b4d5d14f5bf7fe838c19a98beb6c4bd1c3 |
| hovercard-subject-tag | issue:3321421894 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc-gen-python/90/issue_layout |
| twitter:image | https://opengraph.githubassets.com/681d5719c567c8690e59f56aa9ac3f7eed6764f37201df67a8b83ecf3ebc8fb9/sqlc-dev/sqlc-gen-python/issues/90 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/681d5719c567c8690e59f56aa9ac3f7eed6764f37201df67a8b83ecf3ebc8fb9/sqlc-dev/sqlc-gen-python/issues/90 |
| og:image:alt | Getting MySQL syntax error when trying to register users - Parameter binding issue What I'm trying to do I'm building a FastAPI application with MySQL and using sqlc to generate my database reposit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | santinalbrowns |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc-gen-python git https://github.com/sqlc-dev/sqlc-gen-python.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 548530161 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc-gen-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 548530161 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc-gen-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width