Title: Codegen not producing nullable output values when using LEFT Joins and subqueries (GO) · Issue #4117 · sqlc-dev/sqlc · GitHub
Open Graph Title: Codegen not producing nullable output values when using LEFT Joins and subqueries (GO) · Issue #4117 · sqlc-dev/sqlc
X Title: Codegen not producing nullable output values when using LEFT Joins and subqueries (GO) · Issue #4117 · sqlc-dev/sqlc
Description: Version 1.30.0 What happened? Hello, the problem i stumbled on is the follwoing. If i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nullable. If i now use this query -- name: ...
Open Graph Description: Version 1.30.0 What happened? Hello, the problem i stumbled on is the follwoing. If i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nul...
X Description: Version 1.30.0 What happened? Hello, the problem i stumbled on is the follwoing. If i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nul...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/4117
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Codegen not producing nullable output values when using LEFT Joins and subqueries (GO)","articleBody":"### Version\n\n1.30.0\n\n### What happened?\n\nHello, the problem i stumbled on is the follwoing.\n\nIf i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nullable. \n\nIf i now use this query\n\n```SQL\n-- name: TEST :many\nSELECT * FROM a AS table_a\nLEFT JOIN (SELECT * FROM b WHERE b.name is not null) si ON si.a_id = table_a.id;\n```\n\nThe output is this:\n\n```go\ntype TESTRow struct {\n\tID uuid.UUID\n\tName pgtype.Text\n\tID_2 uuid.UUID\n\tAID uuid.UUID\n\tName_2 pgtype.Text\n}\n```\n\nAs you can see. The Properties (IDs) from table b are uuid.UUID and not pointers or other nullable values. This is not working and will produce errors during scanning.\n\nIf the LEFT JOIN is done without a subquery it works as expected:\n\nThe following query:\n\n```SQL\n-- name: TEST2 :many\nSELECT * FROM a AS table_a\nLEFT JOIN b AS table_b ON table_b.a_id = table_a.id\nWHERE table_b.name is not null;\n```\n\nIs generting this output:\n```go\ntype TEST2Row struct {\n\tID uuid.UUID\n\tName pgtype.Text\n\tID_2 *uuid.UUID\n\tAID *uuid.UUID\n\tName_2 pgtype.Text\n}\n```\nI assume this Problem can also be reproduced with right joins. \n\n\n### Relevant log output\n\n```shell\n\n```\n\n### Database schema\n\n```sql\nSchema:\n\nCREATE TABLE a (\n id uuid PRIMARY KEY,\n name TEXT\n);\n\nCREATE TABLE b (\n id uuid PRIMARY KEY,\n a_id uuid NOT NULL REFERENCES a (id),\n name TEXT\n);\n```\n\n### SQL queries\n\n```sql\n\n```\n\n### Configuration\n\n```yaml\nversion: \"2\"\nsql:\n - schema: \"../../../../migrations\"\n queries: \".\"\n engine: \"postgresql\"\n gen:\n go:\n package: internal\n out: \"../\"\n sql_package: \"pgx/v5\"\n overrides:\n - db_type: \"uuid\"\n nullable: false\n go_type:\n import: \"github.com/google/uuid\"\n type: \"UUID\"\n - db_type: \"uuid\"\n nullable: true\n go_type:\n import: \"github.com/google/uuid\"\n type: \"UUID\"\n pointer: true\n```\n\n### Playground URL\n\n_No response_\n\n### What operating system are you using?\n\nmacOS\n\n### What database engines are you using?\n\nPostgreSQL\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/werjo-gridfuse","@type":"Person","name":"werjo-gridfuse"},"datePublished":"2025-09-29T07:41:19Z","url":"https://github.com/sqlc-dev/sqlc/issues/4117"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:ef7e76c7-aab4-53f3-3508-182b65ab014e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF80:2F9718:1DBFC85:27E2AB2:6B017AAC |
| html-safe-nonce | 7e7c1a89ad2cfeed4b8cda9411a30e872f323c15a5ba2f2bd0c43fd9016678a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjgwOjJGOTcxODoxREJGQzg1OjI3RTJBQjI6NkIwMTdBQUMiLCJ2aXNpdG9yX2lkIjoiMjA4MzcyNzQxMTQ5NjcxMjg3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd7135a6dfacf0aed3ac529a7d2bc46f8388ea6fd8681ad5f84f6caba77bd676 |
| hovercard-subject-tag | issue:3463664798 |
| 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/4117/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4329e0b3c5961b7d9d340a716f02023f3d1b58a1baf5f2813726d5fc59f5f334/sqlc-dev/sqlc/issues/4117 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4329e0b3c5961b7d9d340a716f02023f3d1b58a1baf5f2813726d5fc59f5f334/sqlc-dev/sqlc/issues/4117 |
| og:image:alt | Version 1.30.0 What happened? Hello, the problem i stumbled on is the follwoing. If i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nul... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | werjo-gridfuse |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width