Title: pgx parameter nullability inference bugs · Issue #4336 · sqlc-dev/sqlc · GitHub
Open Graph Title: pgx parameter nullability inference bugs · Issue #4336 · sqlc-dev/sqlc
X Title: pgx parameter nullability inference bugs · Issue #4336 · sqlc-dev/sqlc
Description: Version 1.30.0 What happened? Sqlc’s parameter nullability inference is inconsistent in many cases in the current implementation. The expected rule appears to be: Nullable parameters should always use nullable types Non-null parameters s...
Open Graph Description: Version 1.30.0 What happened? Sqlc’s parameter nullability inference is inconsistent in many cases in the current implementation. The expected rule appears to be: Nullable parameters should always ...
X Description: Version 1.30.0 What happened? Sqlc’s parameter nullability inference is inconsistent in many cases in the current implementation. The expected rule appears to be: Nullable parameters should always ...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/4336
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pgx parameter nullability inference bugs","articleBody":"### Version\n\n1.30.0\n\n### What happened?\n\nSqlc’s parameter nullability inference is inconsistent in many cases in the current implementation.\n\nThe expected rule appears to be:\n- Nullable parameters should always use nullable types\n- Non-null parameters should always use non-null types\n- `sqlc.narg(...)` is the explicit way to force a nullable parameter\n\nIn the docs:\n- \"sqlc infers the nullability of any specified parameters, and often does exactly what you want. If you want finer control over the nullability of your parameters, you may use `sqlc.narg()`\"\n- \"for structs, null values are represented using the appropriate type from the database/sql or pgx package.\"\n\nThere are many correct e2e tests that handle nullability correctly but also some that don't.\n\nWe of course want parameters to match the types in structs by default. If you have `pgtype.Int4` while really that parameter is NOT NULL, that's dangerous. I found multiple occurrences of this but only when `sqlc.yaml` included `pgx`. I don’t see a convincing non-pgx nullability bug in the e2e tests\n\nIn `internal/endtoend/testdata/insert_select_param/postgresql/pgx/`:\n```sql\n-- schema.sql\nCREATE TABLE authors (\n id BIGSERIAL PRIMARY KEY,\n name text NOT NULL,\n bio text\n);\n```\n\n```sql\n-- query.sql\n-- name: InsertSelect :exec\nINSERT INTO authors (id, name, bio) \nSELECT @id, name, bio\nFROM authors\nWHERE name = @name;\n```\n\n```sql\n-- query.sql\n-- name: InsertSelect :exec\nINSERT INTO authors (id, name, bio) \nSELECT @id, name, bio\nFROM authors\nWHERE name = @name;\n```\n\n```go\n// query.sql.go\npackage querytest\n\nimport (\n\t\"context\"\n\n\t\"github.com/jackc/pgx/v5/pgtype\"\n)\n\nconst insertSelect = `-- name: InsertSelect :exec\nINSERT INTO authors (id, name, bio) \nSELECT $1, name, bio\nFROM authors\nWHERE name = $2\n`\n\ntype InsertSelectParams struct {\n\tID pgtype.Int8\n\tName pgtype.Text\n}\n\nfunc (q *Queries) InsertSelect(ctx context.Context, arg InsertSelectParams) error {\n\t_, err := q.db.Exec(ctx, insertSelect, arg.ID, arg.Name)\n\treturn err\n}\n```\n\nClearly we see that `name` is supposed to be NOT NULL and yet it takes on the type `pgtype.Text`. The same thing happens in `nested_select`, `select_subquery`, and `unnest_star`.\n\n### Relevant log output\n\n```shell\n\n```\n\n### Database schema\n\n```sql\n\n```\n\n### SQL queries\n\n```sql\n\n```\n\n### Configuration\n\n```yaml\n\n```\n\n### Playground URL\n\n_No response_\n\n### What operating system are you using?\n\n_No response_\n\n### What database engines are you using?\n\n_No response_\n\n### What type of code are you generating?\n\n_No response_","author":{"url":"https://github.com/qykr","@type":"Person","name":"qykr"},"datePublished":"2026-03-11T08:25:26Z","url":"https://github.com/sqlc-dev/sqlc/issues/4336"}
| 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:148b6d02-5641-2ee2-c4f3-6f40280a6d26 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A2FE:14ECB:251FF4D:2F28BC8:6B018B72 |
| html-safe-nonce | 18a7c32ed82b61d18b46e173d859e6d8ac9a8b1b5add8286d7e2de32012cf816 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkZFOjE0RUNCOjI1MUZGNEQ6MkYyOEJDODo2QjAxOEI3MiIsInZpc2l0b3JfaWQiOiIyNzgxMjY2OTM0MDA2NjQ3NjY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0795582f460bedf1051922d69c3344097fc74fd83d72563cb533f2e507a73f84 |
| hovercard-subject-tag | issue:4056687476 |
| 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/4336/issue_layout |
| twitter:image | https://opengraph.githubassets.com/61c2285dab8f68ff29fd6f0d1064434ccd351aed7afbe8ef914be863f9966382/sqlc-dev/sqlc/issues/4336 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/61c2285dab8f68ff29fd6f0d1064434ccd351aed7afbe8ef914be863f9966382/sqlc-dev/sqlc/issues/4336 |
| og:image:alt | Version 1.30.0 What happened? Sqlc’s parameter nullability inference is inconsistent in many cases in the current implementation. The expected rule appears to be: Nullable parameters should always ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | qykr |
| 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