Title: Left Join not generating correct Null* Types · Issue #1334 · sqlc-dev/sqlc · GitHub
Open Graph Title: Left Join not generating correct Null* Types · Issue #1334 · sqlc-dev/sqlc
X Title: Left Join not generating correct Null* Types · Issue #1334 · sqlc-dev/sqlc
Description: Version 1.11.0 What happened? After updating to 1.11.0, the code generated when using LEFT JOIN on tables seems to be incorrect. For the queries and schema given below, I'd expect the following code to be generated: ... type GetSuggested...
Open Graph Description: Version 1.11.0 What happened? After updating to 1.11.0, the code generated when using LEFT JOIN on tables seems to be incorrect. For the queries and schema given below, I'd expect the following cod...
X Description: Version 1.11.0 What happened? After updating to 1.11.0, the code generated when using LEFT JOIN on tables seems to be incorrect. For the queries and schema given below, I'd expect the following...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/1334
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Left Join not generating correct Null* Types","articleBody":"### Version\n\n1.11.0\n\n### What happened?\n\nAfter updating to 1.11.0, the code generated when using `LEFT JOIN` on tables seems to be incorrect.\r\nFor the queries and schema given below, I'd expect the following code to be generated:\r\n```go\r\n...\r\ntype GetSuggestedUsersByIDRow struct {\r\n\tUserID uuid.UUID\r\n\tUserNickname string\r\n\tUserEmail string\r\n\tUserDisplayName string\r\n\tUserPassword sql.NullString\r\n\tUserGoogleID sql.NullString\r\n\tUserAppleID sql.NullString\r\n\tUserBio string\r\n\tUserCreatedAt time.Time\r\n\tUserAvatarID uuid.NullUUID\r\n\tMediaID uuid.NullUUID\r\n\tMediaCreatedAt sql.NullTime\r\n\tMediaHash sql.NullString\r\n\tMediaDirectory sql.NullString\r\n\tMediaAuthorID uuid.NullUUID\r\n\tMediaWidth sql.NullInt32\r\n\tMediaHeight sql.NullInt32\r\n}\r\n...\r\n```\r\nThis is the output when generating queries using `1.10.0`.\r\nInstead, with `1.11.0`, I get:\r\n```go\r\n...\r\ntype GetSuggestedUsersByIDRow struct {\r\n\tUserID uuid.UUID\r\n\tUserNickname string\r\n\tUserEmail string\r\n\tUserDisplayName string\r\n\tUserPassword sql.NullString\r\n\tUserGoogleID sql.NullString\r\n\tUserAppleID sql.NullString\r\n\tUserBio string\r\n\tUserCreatedAt time.Time\r\n\tUserAvatarID uuid.NullUUID\r\n\tMediaID uuid.UUID\r\n\tMediaCreatedAt time.Time\r\n\tMediaHash string\r\n\tMediaDirectory string\r\n\tMediaAuthorID uuid.UUID\r\n\tMediaWidth int32\r\n\tMediaHeight int32\r\n}\r\n...\r\n```\r\nYou can see that the joined table (the `media`), should have Null* types, instead of the plain regular types.\n\n### Relevant log output\n\n_No response_\n\n### Database schema\n\n```sql\nCREATE TABLE \"users\"\r\n(\r\n \"user_id\" uuid PRIMARY KEY,\r\n \"user_nickname\" VARCHAR(30) UNIQUE NOT NULL,\r\n \"user_email\" TEXT UNIQUE NOT NULL,\r\n \"user_display_name\" TEXT NOT NULL,\r\n \"user_password\" TEXT NULL,\r\n \"user_google_id\" TEXT UNIQUE NULL,\r\n \"user_apple_id\" TEXT UNIQUE NULL,\r\n \"user_bio\" VARCHAR(160) NOT NULL DEFAULT '',\r\n \"user_created_at\" TIMESTAMP NOT NULL DEFAULT (NOW()),\r\n \"user_avatar_id\" uuid UNIQUE NULL\r\n);\r\n\r\nCREATE TABLE \"media\"\r\n(\r\n \"media_id\" uuid PRIMARY KEY,\r\n \"media_created_at\" TIMESTAMP NOT NULL DEFAULT (NOW()),\r\n \"media_hash\" TEXT NOT NULL,\r\n \"media_directory\" TEXT NOT NULL,\r\n \"media_author_id\" uuid NOT NULL,\r\n \"media_width\" INT NOT NULL,\r\n \"media_height\" INT NOT NULL\r\n);\r\n\r\nALTER TABLE \"users\"\r\n ADD FOREIGN KEY (\"user_avatar_id\") REFERENCES \"media\" (\"media_id\") ON DELETE SET DEFAULT ON UPDATE CASCADE;\n```\n\n\n### SQL queries\n\n```sql\nCREATE TABLE \"users\"\r\n(\r\n \"user_id\" uuid PRIMARY KEY,\r\n \"user_nickname\" VARCHAR(30) UNIQUE NOT NULL,\r\n \"user_email\" TEXT UNIQUE NOT NULL,\r\n \"user_display_name\" TEXT NOT NULL,\r\n \"user_password\" TEXT NULL,\r\n \"user_google_id\" TEXT UNIQUE NULL,\r\n \"user_apple_id\" TEXT UNIQUE NULL,\r\n \"user_bio\" VARCHAR(160) NOT NULL DEFAULT '',\r\n \"user_created_at\" TIMESTAMP NOT NULL DEFAULT (NOW()),\r\n \"user_avatar_id\" uuid UNIQUE NULL\r\n);\r\n\r\nCREATE TABLE \"media\"\r\n(\r\n \"media_id\" uuid PRIMARY KEY,\r\n \"media_created_at\" TIMESTAMP NOT NULL DEFAULT (NOW()),\r\n \"media_hash\" TEXT NOT NULL,\r\n \"media_directory\" TEXT NOT NULL,\r\n \"media_author_id\" uuid NOT NULL,\r\n \"media_width\" INT NOT NULL,\r\n \"media_height\" INT NOT NULL\r\n);\r\n\r\nALTER TABLE \"users\"\r\n ADD FOREIGN KEY (\"user_avatar_id\") REFERENCES \"media\" (\"media_id\") ON DELETE SET DEFAULT ON UPDATE CASCADE;\r\n\r\n-- name: GetSuggestedUsersByID :many\r\nSELECT DISTINCT u.*, m.*\r\nFROM users u\r\n LEFT JOIN media m ON u.user_avatar_id = m.media_id\r\nWHERE u.user_id != @user_id\r\nLIMIT @user_imit;\n```\n\n\n### Configuration\n\n```yaml\n{\r\n \"version\": \"1\",\r\n \"packages\": [\r\n {\r\n \"path\": \"db\",\r\n \"engine\": \"postgresql\",\r\n \"schema\": \"query.sql\",\r\n \"queries\": \"query.sql\"\r\n }\r\n ]\r\n}\n```\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/fr3fou","@type":"Person","name":"fr3fou"},"datePublished":"2021-12-08T17:34:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/1334/sqlc/issues/1334"}
| 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:c9c536e9-f0cb-3b19-7740-4f152544e3c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A12A:18F0F4:2FE269:3EAE2E:6A517E03 |
| html-safe-nonce | 3895fed289a88699b5bbd86f8c9a2949db8725f72ae17bf43636d5d7f777be0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTJBOjE4RjBGNDoyRkUyNjk6M0VBRTJFOjZBNTE3RTAzIiwidmlzaXRvcl9pZCI6IjE1MTQ5Njg0MjAzMDY3NDY4ODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 839e6cb3e9f4425faf4a6c40e4477dff0d344f3280c417de608a2dd57712965b |
| hovercard-subject-tag | issue:1074655283 |
| 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/1334/issue_layout |
| twitter:image | https://opengraph.githubassets.com/30f7cca1577bfe178170992e79f4e2fd0ba8017fbf179ed64bfedbe42abaf1eb/sqlc-dev/sqlc/issues/1334 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/30f7cca1577bfe178170992e79f4e2fd0ba8017fbf179ed64bfedbe42abaf1eb/sqlc-dev/sqlc/issues/1334 |
| og:image:alt | Version 1.11.0 What happened? After updating to 1.11.0, the code generated when using LEFT JOIN on tables seems to be incorrect. For the queries and schema given below, I'd expect the following cod... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fr3fou |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | d01c62704ef24df49056c63892a149b775e1353d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width