Title: Go panics when sub query is missing an alias with sqlite · Issue #3514 · sqlc-dev/sqlc · GitHub
Open Graph Title: Go panics when sub query is missing an alias with sqlite · Issue #3514 · sqlc-dev/sqlc
X Title: Go panics when sub query is missing an alias with sqlite · Issue #3514 · sqlc-dev/sqlc
Description: Version 1.26.0 What happened? I accidentally left an alias off my subquery and I got a panic instead of a useful error message. Failing playground without alias (included below as well): https://play.sqlc.dev/p/9bd88a936c60738a57503c6314...
Open Graph Description: Version 1.26.0 What happened? I accidentally left an alias off my subquery and I got a panic instead of a useful error message. Failing playground without alias (included below as well): https://pl...
X Description: Version 1.26.0 What happened? I accidentally left an alias off my subquery and I got a panic instead of a useful error message. Failing playground without alias (included below as well): https://pl...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/3514
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Go panics when sub query is missing an alias with sqlite","articleBody":"### Version\n\n1.26.0\n\n### What happened?\n\nI accidentally left an alias off my subquery and I got a panic instead of a useful error message.\r\n\r\nFailing playground without alias (included below as well): https://play.sqlc.dev/p/9bd88a936c60738a57503c6314f5805316327b3dbf51a03c49518ff729382b44\r\n\r\nPassing playground with alias: https://play.sqlc.dev/p/47e54486a69100bf2e6e61436518f642835859e73a7ba42ab89f0f74234be50c\r\n\r\nExample with postgres that gives a useful error message instead of the panic: https://play.sqlc.dev/p/dd2d6eaf25d9bef2b07e1cd7dc5a4b949694ba6d200b419724d13a513c1eaf1a\n\n### Relevant log output\n\n```shell\npanic: runtime error: invalid memory address or nil pointer dereference\r\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10d0247]\r\n\r\ngoroutine 6 [running]:\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).sourceTables(0xc00049c008, 0xc00048ed50, {0x1d84f80?, 0xc0009d9ad0?})\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/output_columns.go:601 +0xaa7\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).outputColumns(0xc00049c008, 0xc00048ed50, {0x1d84f80, 0xc0009d9ad0})\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/output_columns.go:55 +0x45\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler)._analyzeQuery(0xc00049c008, 0xc000f8fde0, {0xc000062fcc, 0x83}, 0x1)\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/analyze.go:180 +0xced\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).analyzeQuery(...)\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/analyze.go:110\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQuery(0xc00049c008, {0x1d85140, 0xc000f8fde0}, {0xc000062c00, 0x5d5}, {{0x0, 0x0, {0x0, 0x0}, 0x0, ...}})\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/parse.go:103 +0x5d5\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).parseQueries(0xc00049c008, {{0x0, 0x0, {0x0, 0x0}, 0x0, 0x0, 0x0, 0x0}})\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/compile.go:81 +0x467\r\ngithub.com/sqlc-dev/sqlc/internal/compiler.(*Compiler).ParseQueries(...)\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/compiler/engine.go:76\r\ngithub.com/sqlc-dev/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0x0, 0x0}, {0xc00047629a, 0x6}, ...}, ...)\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/cmd/generate.go:322 +0x30b\r\ngithub.com/sqlc-dev/sqlc/internal/cmd.processQuerySets.func1()\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/github.com/sqlc-dev/sqlc@v1.26.0/internal/cmd/process.go:107 +0x877\r\ngolang.org/x/sync/errgroup.(*Group).Go.func1()\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:78 +0x56\r\ncreated by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1\r\n /home/user/.asdf/installs/golang/1.22.2/packages/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:75 +0x96\n```\n\n\n### Database schema\n\n```sql\nCREATE TABLE clients (\r\n id INTEGER NOT NULL, \r\n created_at DATETIME DEFAULT (CURRENT_TIMESTAMP) NOT NULL, \r\n updated_at DATETIME DEFAULT (CURRENT_TIMESTAMP) NOT NULL, \r\n deleted_at DATETIME, \r\n external_id VARCHAR(36) NOT NULL, \r\n meta JSON NOT NULL, \r\n PRIMARY KEY (id), \r\n UNIQUE (external_id)\r\n);\n```\n\n\n### SQL queries\n\n```sql\n-- name: GetNextClientID :one\r\nSELECT max(external_id) FROM (\r\n SELECT external_id FROM clients\r\n ORDER BY external_id\r\n LIMIT ?\r\n);\n```\n\n\n### Configuration\n\n```yaml\nversion: \"2\"\r\nsql:\r\n - engine: \"sqlite\"\r\n queries: \"internal/database/query.sql\"\r\n schema: \"internal/database/migrations\"\r\n gen:\r\n go:\r\n package: \"database\"\r\n out: \"internal/database\"\n```\n\n\n### Playground URL\n\nhttps://play.sqlc.dev/p/9bd88a936c60738a57503c6314f5805316327b3dbf51a03c49518ff729382b44\n\n### What operating system are you using?\n\nLinux\n\n### What database engines are you using?\n\nSQLite\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/leetrout","@type":"Person","name":"leetrout"},"datePublished":"2024-08-02T03:54:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/3514/sqlc/issues/3514"}
| 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:4304e2b4-dd67-1f3b-4b62-ce4ab91b398b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 816A:1DCECA:7FCF93:B6514B:6A51060F |
| html-safe-nonce | a08157f4cb7353b6e6c267a58912bc85784c1bf75244e227b8664b75b757c4d5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTZBOjFEQ0VDQTo3RkNGOTM6QjY1MTRCOjZBNTEwNjBGIiwidmlzaXRvcl9pZCI6IjI1NDYyNTQ3NTAyODM3OTM5MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d378a8f825a9d433705db0682aeec5c5ef6c00a2c345c0a6194e119a9fb76cff |
| hovercard-subject-tag | issue:2443952110 |
| 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/3514/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c90bca160a2ebe936102a31ec9d9e28f88f9760c8df7f1f205d7ae1d140b967f/sqlc-dev/sqlc/issues/3514 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c90bca160a2ebe936102a31ec9d9e28f88f9760c8df7f1f205d7ae1d140b967f/sqlc-dev/sqlc/issues/3514 |
| og:image:alt | Version 1.26.0 What happened? I accidentally left an alias off my subquery and I got a panic instead of a useful error message. Failing playground without alias (included below as well): https://pl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | leetrout |
| hostname | github.com |
| expected-hostname | github.com |
| None | b076e100febaa00374cd89239f915d00dd3187f7c68b12bc2b7688181305344d |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| 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 | 2d129404fc45ea64edb1b98567c53e55b395536f |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width