René's URL Explorer Experiment


Title: Updating Rows: Documented syntax doesn't produce expected result for MySQL and Sqlite · Issue #3697 · sqlc-dev/sqlc · GitHub

Open Graph Title: Updating Rows: Documented syntax doesn't produce expected result for MySQL and Sqlite · Issue #3697 · sqlc-dev/sqlc

X Title: Updating Rows: Documented syntax doesn't produce expected result for MySQL and Sqlite · Issue #3697 · sqlc-dev/sqlc

Description: Version 1.27.0 What happened? High Level The documentation for updating rows appears to be incomplete, resulting in an error for Sqlite and a silent-but-incorrect generation for MySQL. It appears that the $1 placeholders used in the docu...

Open Graph Description: Version 1.27.0 What happened? High Level The documentation for updating rows appears to be incomplete, resulting in an error for Sqlite and a silent-but-incorrect generation for MySQL. It appears t...

X Description: Version 1.27.0 What happened? High Level The documentation for updating rows appears to be incomplete, resulting in an error for Sqlite and a silent-but-incorrect generation for MySQL. It appears t...

Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/3697

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Updating Rows: Documented syntax doesn't produce expected result for MySQL and Sqlite","articleBody":"### Version\n\n1.27.0\n\n### What happened?\n\n# High Level\r\nThe [documentation](https://github.com/sqlc-dev/sqlc/blob/main/docs/howto/update.md) for updating rows appears to be incomplete, resulting in an error for Sqlite and a silent-but-incorrect generation for MySQL. It appears that the `$1` placeholders used in the documentation are not valid for these two backends (but is valid for PostgreSQL,) and that `?` should be used for the Sqlite and MySQL backends.\r\n\r\n# Suggested resolution\r\nUpdate the documentation to reflect differences in SQL dialects. As someone unfamiliar with PostgreSQL it wasn't clear if the use of `$1` was specific to sqlc or not, so having a note and examples using the other backends would be great.\r\n\r\nThe silent failure to generate expected MySQL outputs (see code block at bottom) is an issue that isn't as clear to fix. The user will quickly see that the generated functions don't behave as expected, but there's no output or indication as to what went wrong. One place I could see this potentially occurring is a codebase that uses PostgreSQL and then adds the MySQL backend using the same queries - it's possible that they are \"compatible\" enough to silently pass through. Perhaps `sqlc` could emit a warning if it detects the `$#` syntax within a query targeting MySQL? \r\n\r\nIf possible it might also be helpful to have nicer error messages that catch this case for the Sqlite version too, indicating that the syntax might be using the wrong dialect; I'm not sure how viable such a warning would be to implement.\r\n\r\n# What I did\r\n\r\nsqcl 1.27.0, generating go code\r\n\r\nWhen following the [documentation](https://github.com/sqlc-dev/sqlc/blob/main/docs/howto/update.md) for updating rows, I ran into two issues. When generating for sqlite, the `$1` syntax demonstrated in the documentation's `UPDATE authors SET bio = $1;` results in the error below. When generating for mysql, the syntax does not result in an error but does not generate the expected go code.\r\n\r\n## Sqlite Reproduction\r\n\r\n1. Using the attached configuration, comment out the mysql portion of the yaml\r\n2. Run `sqlc generate`\r\n3. Note the error output attached below\r\n4. Edit the `query.sql` to only include the `UpdateExampleGood` query\r\n5. Run `sqlc generate`\r\n6. Note no error output\r\n7. Note that `sqlite/query.sql.go` contains the expected UpdateExampleParams struct\r\n\r\n## MySQL Reproduction\r\n\r\n1. Using the attached configuration, comment out the sqlite portion of the yaml\r\n2. Revert the `query.sql` to the attached version if it was edited\r\n3. Run `sqlc generate`\r\n4. Note no error output\r\n5. Note that `mysql/query.sql.go` contains two Query functions\r\n    - `UpdateExample` does not have an associated Params struct\r\n    - `UpdateExampleGood` does have the expected Params struct\r\n\r\n\r\n## Example MySQL output with expected and unexpected generated functions\r\n\r\n```go\r\n// Code generated by sqlc. DO NOT EDIT.\r\n// versions:\r\n//   sqlc v1.27.0\r\n// source: query.sql\r\n\r\npackage example_issue\r\n\r\nimport (\r\n\t\"context\"\r\n)\r\n\r\nconst updateExample = `-- name: UpdateExample :exec\r\nUPDATE Example SET name = $2 WHERE id = $1\r\n`\r\n\r\n/ / NOTE: No Params struct for the `$` syntax, but the function is generated anyway\r\nfunc (q *Queries) UpdateExample(ctx context.Context) error {\r\n\t_, err := q.db.ExecContext(ctx, updateExample)\r\n\treturn err\r\n}\r\n\r\nconst updateExampleGood = `-- name: UpdateExampleGood :exec\r\nUPDATE Example SET name = ? WHERE id = ?\r\n`\r\n\r\ntype UpdateExampleGoodParams struct {\r\n\tName string\r\n\tID   int32\r\n}\r\n\r\n// NOTE: Params struct is generated with the `?` syntax\r\nfunc (q *Queries) UpdateExampleGood(ctx context.Context, arg UpdateExampleGoodParams) error {\r\n\t_, err := q.db.ExecContext(ctx, updateExampleGood, arg.Name, arg.ID)\r\n\treturn err\r\n}\r\n\r\n\r\n```\n\n### Relevant log output\n\n```shell\n** Running `sqlc generate` with sqlite backend:\r\n\r\nline 2:26 no viable alternative at input 'UPDATE Example SET name = $'\r\n# package example_issue\r\nquery.sql:1:1: no viable alternative at input 'UPDATE Example SET name = $'\r\n\r\n** No log outputs for mysql backend\n```\n\n\n### Database schema\n\n```sql\nCREATE TABLE IF NOT EXISTS Example (\r\n    id INTEGER NOT NULL,\r\n    name TEXT NOT NULL\r\n);\n```\n\n\n### SQL queries\n\n```sql\n-- This query fails to generate for sqlite, and doesn't generate Params for mysql\r\n-- name: UpdateExample :exec\r\nUPDATE Example SET name = $2 WHERE id = $1;\r\n\r\n-- This version produces the expected output for both\r\n-- name: UpdateExampleGood :exec\r\nUPDATE Example SET name = ? WHERE id = ?;\n```\n\n\n### Configuration\n\n```yaml\nversion: \"2\"\r\nsql:\r\n  - engine: \"mysql\"\r\n    queries: \"query.sql\"\r\n    schema: \"schema.sql\"\r\n    gen:\r\n      go:\r\n        package: \"example_issue\"\r\n        out: \"mysql\"  \r\n  - engine: \"sqlite\"\r\n    queries: \"query.sql\"\r\n    schema: \"schema.sql\"\r\n    gen:\r\n      go:\r\n        package: \"example_issue\"\r\n        out: \"sqlite\"\r\n  \r\n  \r\n  # NOTE: Included for completeness; to use you need to remove the `UpdateExampleGood` query\r\n  # since it doesn't have compatible syntax but does work with the documented $1, $2 syntax \r\n  # - engine: \"postgresql\"\r\n  #   queries: \"query.sql\"\r\n  #   schema: \"schema.sql\"\r\n  #   gen:\r\n  #     go:\r\n  #       package: \"example_issue\"\r\n  #       out: \"postgresql\"\n```\n\n\n### Playground URL\n\n_No response_\n\n### What operating system are you using?\n\nLinux\n\n### What database engines are you using?\n\nMySQL, SQLite\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/ookjosh","@type":"Person","name":"ookjosh"},"datePublished":"2024-11-09T03:03:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/3697/sqlc/issues/3697"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:726083cb-ede7-0798-e093-272fe1051ee0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9C7E:18EF1B:8C66F49:C33D07F:6A50726F
html-safe-nonce4628fc1ef9e9d76b4ffb5200de76022ce2930bacc8c6fc19ddbcd5a3f96f2754
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzdFOjE4RUYxQjo4QzY2RjQ5OkMzM0QwN0Y6NkE1MDcyNkYiLCJ2aXNpdG9yX2lkIjoiMzM2NzQwMzI5NDEzMzYxMzE2NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac37229c5dc09328a44ececee25d18575d86ad7085382dad50d6d4dec010a8f5f4
hovercard-subject-tagissue:2645528808
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc/3697/issue_layout
twitter:imagehttps://opengraph.githubassets.com/af041e43d1d0b1558ffb3d5de2045b25fc1987e00b1188e4826a0535241499de/sqlc-dev/sqlc/issues/3697
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/af041e43d1d0b1558ffb3d5de2045b25fc1987e00b1188e4826a0535241499de/sqlc-dev/sqlc/issues/3697
og:image:altVersion 1.27.0 What happened? High Level The documentation for updating rows appears to be incomplete, resulting in an error for Sqlite and a silent-but-incorrect generation for MySQL. It appears t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameookjosh
hostnamegithub.com
expected-hostnamegithub.com
Noned6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb
turbo-cache-controlno-preview
go-importgithub.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git
octolytics-dimension-user_id136738596
octolytics-dimension-user_loginsqlc-dev
octolytics-dimension-repository_id193160679
octolytics-dimension-repository_nwosqlc-dev/sqlc
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id193160679
octolytics-dimension-repository_network_root_nwosqlc-dev/sqlc
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/sqlc-dev/sqlc/issues/3697#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc%2Fissues%2F3697
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc%2Fissues%2F3697
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=sqlc-dev%2Fsqlc
Reloadhttps://github.com/sqlc-dev/sqlc/issues/3697
Reloadhttps://github.com/sqlc-dev/sqlc/issues/3697
Reloadhttps://github.com/sqlc-dev/sqlc/issues/3697
Please reload this pagehttps://github.com/sqlc-dev/sqlc/issues/3697
sqlc-dev https://github.com/sqlc-dev
sqlchttps://github.com/sqlc-dev/sqlc
Notifications https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Fork 1.1k https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Star 18k https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc
Code https://github.com/sqlc-dev/sqlc
Issues 597 https://github.com/sqlc-dev/sqlc/issues
Pull requests 106 https://github.com/sqlc-dev/sqlc/pulls
Discussions https://github.com/sqlc-dev/sqlc/discussions
Actions https://github.com/sqlc-dev/sqlc/actions
Projects https://github.com/sqlc-dev/sqlc/projects
Security and quality 0 https://github.com/sqlc-dev/sqlc/security
Insights https://github.com/sqlc-dev/sqlc/pulse
Code https://github.com/sqlc-dev/sqlc
Issues https://github.com/sqlc-dev/sqlc/issues
Pull requests https://github.com/sqlc-dev/sqlc/pulls
Discussions https://github.com/sqlc-dev/sqlc/discussions
Actions https://github.com/sqlc-dev/sqlc/actions
Projects https://github.com/sqlc-dev/sqlc/projects
Security and quality https://github.com/sqlc-dev/sqlc/security
Insights https://github.com/sqlc-dev/sqlc/pulse
#4036https://github.com/sqlc-dev/sqlc/pull/4036
Updating Rows: Documented syntax doesn't produce expected result for MySQL and Sqlitehttps://github.com/sqlc-dev/sqlc/issues/3697#top
#4036https://github.com/sqlc-dev/sqlc/pull/4036
📚 mysqlhttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Abooks%3A%20mysql%22
📚 sqlitehttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Abooks%3A%20sqlite%22
🔧 golanghttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Awrench%3A%20golang%22
bugSomething isn't workinghttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/ookjosh
ookjoshhttps://github.com/ookjosh
on Nov 9, 2024https://github.com/sqlc-dev/sqlc/issues/3697#issue-2645528808
documentationhttps://github.com/sqlc-dev/sqlc/blob/main/docs/howto/update.md
documentationhttps://github.com/sqlc-dev/sqlc/blob/main/docs/howto/update.md
📚 mysqlhttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Abooks%3A%20mysql%22
📚 sqlitehttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Abooks%3A%20sqlite%22
🔧 golanghttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22%3Awrench%3A%20golang%22
bugSomething isn't workinghttps://github.com/sqlc-dev/sqlc/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.