Title: MySQL left join fields are not sql.Null* · Issue #1271 · sqlc-dev/sqlc · GitHub
Open Graph Title: MySQL left join fields are not sql.Null* · Issue #1271 · sqlc-dev/sqlc
X Title: MySQL left join fields are not sql.Null* · Issue #1271 · sqlc-dev/sqlc
Description: Version 1.10.0 What happened? The following SQL queries (with the schemas) produces different kinds of outputs where it really shouldn't. When you LEFT JOIN 2 tables, the tables which gets joined should have fields of type sql.Null* as t...
Open Graph Description: Version 1.10.0 What happened? The following SQL queries (with the schemas) produces different kinds of outputs where it really shouldn't. When you LEFT JOIN 2 tables, the tables which gets joined s...
X Description: Version 1.10.0 What happened? The following SQL queries (with the schemas) produces different kinds of outputs where it really shouldn't. When you LEFT JOIN 2 tables, the tables which gets join...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/1271
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MySQL left join fields are not sql.Null*","articleBody":"### Version\n\n1.10.0\n\n### What happened?\n\nThe following SQL queries (with the schemas) produces different kinds of outputs where it really shouldn't. When you `LEFT JOIN` 2 tables, the tables which gets joined should have fields of type `sql.Null*` as they can be null. \r\nThis happens on `postgresql` already but **not with mysql**. With mysql the fields are non null fields unless they are already nullable by the original table definition.\n\n### Relevant log output\n\n```shell\nMySQL: \r\n\r\nconst something = `-- name: something :many\r\nSELECT id, name, bio, users.identifier, users.something FROM authors LEFT JOIN users on users.identifier = authors.id\r\n`\r\n\r\ntype somethingRow struct {\r\n\tID int32\r\n\tName string\r\n\tBio sql.NullString\r\n\tIdentifier int32\r\n\tSomething string\r\n}\r\n\r\nfunc (q *Queries) something(ctx context.Context) ([]somethingRow, error) {\r\n\trows, err := q.db.QueryContext(ctx, something)\r\n\tif err != nil {\r\n\t\treturn nil, err\r\n\t}\r\n\t// not so important\r\n}\r\n\r\nPostgreSQL\r\n\r\nconst something = `-- name: something :many\r\nSELECT id, name, bio, users.identifier, users.something FROM authors LEFT JOIN users on users.identifier = authors.id\r\n`\r\n\r\ntype somethingRow struct {\r\n\tID int32\r\n\tName string\r\n\tBio sql.NullString\r\n\tIdentifier sql.NullInt32\r\n\tSomething sql.NullString\r\n}\r\n\r\nfunc (q *Queries) something(ctx context.Context) ([]somethingRow, error) {\r\n\trows, err := q.db.QueryContext(ctx, something)\r\n\tif err != nil {\r\n\t\treturn nil, err\r\n\t}\r\n\t// not so important\r\n}\n```\n\n\n### Database schema\n\n```sql\nCREATE TABLE users (\r\n identifier int PRIMARY KEY,\r\n something text not null\r\n);\r\n\r\nCREATE TABLE authors (\r\n id int PRIMARY KEY,\r\n name text NOT NULL,\r\n bio text\r\n);\n```\n\n\n### SQL queries\n\n```sql\n-- name: something :many\r\nSELECT id, name, bio, users.identifier, users.something FROM authors LEFT JOIN users on users.identifier = authors.id;\r\n\r\n-- name: foo :many\r\nselect * from users;\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\": \"mysql\",\r\n \"schema\": \"query.sql\",\r\n \"queries\": \"query.sql\"\r\n }\r\n ]\r\n}\n```\n\n\n### Playground URL\n\nhttps://play.sqlc.dev/p/3ec9ff982309d7cfa286390a5d69c5488c05e8c36bc5dddab54e726ace13be11\n\n### What operating system are you using?\n\n_No response_\n\n### What database engines are you using?\n\nMySQL\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/gngrchrl","@type":"Person","name":"gngrchrl"},"datePublished":"2021-11-04T22:51:31Z","url":"https://github.com/sqlc-dev/sqlc/issues/1271"}
| 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:3baaf78a-8266-c6d5-ae64-ef760ca160dd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DDF0:96DDF:22AB27C:2BE60EC:6B0174C8 |
| html-safe-nonce | e7f69147eed2ca97515c458f39dbe1ca78242d7907cef2c9d0aef2499754271a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREYwOjk2RERGOjIyQUIyN0M6MkJFNjBFQzo2QjAxNzRDOCIsInZpc2l0b3JfaWQiOiI4ODQ5MzYzNDY5MDE1ODA3MTc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 54e422741bf042bfefc850b63f882fcbfc3c7f014e68eae1951942a417e8c6c2 |
| hovercard-subject-tag | issue:1045280788 |
| 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/1271/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a4945381a6faa46547fd67f5e5336bd83aa3d2caaf39703fd0e48ca8e289cb09/sqlc-dev/sqlc/issues/1271 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a4945381a6faa46547fd67f5e5336bd83aa3d2caaf39703fd0e48ca8e289cb09/sqlc-dev/sqlc/issues/1271 |
| og:image:alt | Version 1.10.0 What happened? The following SQL queries (with the schemas) produces different kinds of outputs where it really shouldn't. When you LEFT JOIN 2 tables, the tables which gets joined s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gngrchrl |
| 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