Title: Nullable enum columns are not recognized as nullable by generated code · Issue #1660 · sqlc-dev/sqlc · GitHub
Open Graph Title: Nullable enum columns are not recognized as nullable by generated code · Issue #1660 · sqlc-dev/sqlc
X Title: Nullable enum columns are not recognized as nullable by generated code · Issue #1660 · sqlc-dev/sqlc
Description: Version 1.10.0 What happened? Generated code causes an error when it tried to scan a row from a table with a nullable enum column. Relevant generated code: type Resource struct { ID int32 `json:"id"` KeyState ResourceKeyState `json:"key_...
Open Graph Description: Version 1.10.0 What happened? Generated code causes an error when it tried to scan a row from a table with a nullable enum column. Relevant generated code: type Resource struct { ID int32 `json:"id...
X Description: Version 1.10.0 What happened? Generated code causes an error when it tried to scan a row from a table with a nullable enum column. Relevant generated code: type Resource struct { ID int32 `json:&qu...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/1660
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Nullable enum columns are not recognized as nullable by generated code","articleBody":"### Version\n\n1.10.0\n\n### What happened?\n\nGenerated code causes an error when it tried to scan a row from a table with a nullable enum column.\r\n\r\nRelevant generated code:\r\n```\r\ntype Resource struct {\r\n\tID int32 `json:\"id\"`\r\n\tKeyState ResourceKeyState `json:\"key_state\"`\r\n}\r\n\r\ntype ResourceKeyState string\r\n\r\nconst (\r\n\tResourceKeyStateNOTYETACTIVE ResourceKeyState = \"NOT_YET_ACTIVE\"\r\n\tResourceKeyStateACTIVE ResourceKeyState = \"ACTIVE\"\r\n\tResourceKeyStateINACTIVE ResourceKeyState = \"INACTIVE\"\r\n\tResourceKeyStateDELETIONSCHEDULED ResourceKeyState = \"DELETION_SCHEDULED\"\r\n)\r\n\r\nfunc (e *ResourceKeyState) Scan(src interface{}) error {\r\n\tswitch s := src.(type) {\r\n\tcase []byte:\r\n\t\t*e = ResourceKeyState(s)\r\n\tcase string:\r\n\t\t*e = ResourceKeyState(s)\r\n\tdefault:\r\n\t\treturn fmt.Errorf(\"unsupported scan type for ResourceKeyState: %T\", src)\r\n\t}\r\n\treturn nil\r\n}\r\n```\r\n\r\nExpected: \r\nGenerated code should recognize that the column can have null values, and scan values from it accordingly.\n\n### Relevant log output\n\n```shell\n{\"log.level\":\"ERROR\",\"@timestamp\":\"2022-06-01T03:58:17.096Z\",\"log.origin\":{\"file.name\":\"\u003cREDACTED>.go\",\"file.line\":179},\"message\":\"sql: Scan error on column index 7, name \\\"key_state\\\": unsupported scan type for ResourceKeyState: \u003cnil> (rest of log message REDACTED)\"}\n```\n\n\n### Database schema\n\n```sql\nCREATE TABLE `resource` (\r\n `id` int(11) NOT NULL AUTO_INCREMENT,\r\n `key_state` enum('NOT_YET_ACTIVE','ACTIVE','INACTIVE','DELETION_SCHEDULED') DEFAULT NULL,\r\n PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n```\n\n\n### SQL queries\n\n```sql\n/* name: GetResourceById :one */\r\nSELECT * FROM resource\r\nWHERE id = ? ;\n```\n\n\n### Configuration\n\n```yaml\n{\r\n \"version\": \"2\",\r\n \"sql\": [\r\n {\r\n \"schema\": \"sqlc/\u003cREDACTED>.sql\",\r\n \"queries\": \"sqlc/\u003cREDACTED>.sqlc.sql\",\r\n \"engine\": \"mysql\",\r\n \"gen\": {\r\n \"go\": {\r\n \"emit_json_tags\": true,\r\n \"package\": \"sqlcgen\",\r\n \"out\": \"components/sqlc\"\r\n }\r\n }\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\nLinux, macOS\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/jackdelab","@type":"Person","name":"jackdelab"},"datePublished":"2022-06-02T17:14:35Z","url":"https://github.com/sqlc-dev/sqlc/issues/1660"}
| 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:3e363eb5-4cef-346b-311e-dab46d9f8862 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94D6:96DDF:24A6ECF:2E6C1F5:6B01805B |
| html-safe-nonce | 8e7cf10797800c7e93a540791a92f8f0ed455a483112982ca529a8e982526224 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEQ2Ojk2RERGOjI0QTZFQ0Y6MkU2QzFGNTo2QjAxODA1QiIsInZpc2l0b3JfaWQiOiI0MzQyMzMyMDk4MzUxMzAwNjk5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 55dd203f93329580a29179020a199439e4f6715ceed291820d89944723f55add |
| hovercard-subject-tag | issue:1258468999 |
| 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/1660/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dde7cae4ae593fe4273c7a16f3aba25ee63b830b4fef48cdbcca6fd980b0b8a6/sqlc-dev/sqlc/issues/1660 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dde7cae4ae593fe4273c7a16f3aba25ee63b830b4fef48cdbcca6fd980b0b8a6/sqlc-dev/sqlc/issues/1660 |
| og:image:alt | Version 1.10.0 What happened? Generated code causes an error when it tried to scan a row from a table with a nullable enum column. Relevant generated code: type Resource struct { ID int32 `json:"id... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jackdelab |
| 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