Title: Support for overriding types · Issue #82 · sqlc-dev/sqlc-gen-python · GitHub
Open Graph Title: Support for overriding types · Issue #82 · sqlc-dev/sqlc-gen-python
X Title: Support for overriding types · Issue #82 · sqlc-dev/sqlc-gen-python
Description: It would be really helpful to have the override functionality available in the go version of sqlc. In combination with the existing pydantic functionality, this would be very useful. e.g., currently JSONB columns are returned with Any ty...
Open Graph Description: It would be really helpful to have the override functionality available in the go version of sqlc. In combination with the existing pydantic functionality, this would be very useful. e.g., currentl...
X Description: It would be really helpful to have the override functionality available in the go version of sqlc. In combination with the existing pydantic functionality, this would be very useful. e.g., currentl...
Opengraph URL: https://github.com/sqlc-dev/sqlc-gen-python/issues/82
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for overriding types","articleBody":"It would be really helpful to have the [override functionality available in the go version of sqlc](https://docs.sqlc.dev/en/stable/howto/overrides.html#overriding-types). In combination with the existing pydantic functionality, this would be very useful.\n\ne.g., currently [`JSONB` columns are returned with `Any`](https://github.com/sqlc-dev/sqlc-gen-python/blob/53fa0b2e3d10c4201f7a5a344d00a560330da3bb/internal/postgresql_type.go#L22-L23) type. I would like to be able to override this behaviour on a per-column basis. This would be useful not only for \"Any\" types, but also for types where a different primitive is desired (e.g. a 3rd party UUID instead of the builtin, like the [go example](https://docs.sqlc.dev/en/stable/howto/overrides.html#overriding-types))\n\n## Given this schema\n\n```sql\n-- schema.sql\nCREATE TABLE some_table (\n id SERIAL NOT NULL,\n payload JSONB NOT NULL\n);\n```\n\n## Current output of `sqlc generate` (uses Any for payload column)\n\n```python\n# db/models.py\n# Code generated by sqlc. DO NOT EDIT.\n# versions:\n# sqlc v1.28.0\nimport pydantic\nfrom typing import Any\n\n\nclass SomeTable(pydantic.BaseModel):\n id: int\n payload: Any\n```\n\n## Desired output (uses custom type for payload column)\n\n```python\n# db/models.py\n# Code generated by sqlc. DO NOT EDIT.\n# versions:\n# sqlc v1.28.0\nimport pydantic\nimport my_lib.models\n\n\nclass SomeTable(pydantic.BaseModel):\n id: int\n payload: my_lib.models.Payload\n```\n\n## How it could work\n\nI would imagine something in the config like:\n\n```yaml\nversion: \"2\"\nplugins:\n - name: py\n wasm:\n url: https://downloads.sqlc.dev/plugin/sqlc-gen-python_1.3.0.wasm\n sha256: fbedae96b5ecae2380a70fb5b925fd4bff58a6cfb1f3140375d098fbab7b3a3c\nsql:\n - schema: \"./schemq.sql\"\n queries: \"./query\"\n engine: postgresql\n codegen:\n - out: ./packages/core/src/core/db\n plugin: py\n options:\n package: core.db\n emit_pydantic_models: true\n overrides: # similar to the go overrides\n - column: \"some_table.payload\"\n py_import: \"my_lib.models\"\n py_type: \"Payload\"\n```","author":{"url":"https://github.com/oliverlambson","@type":"Person","name":"oliverlambson"},"datePublished":"2025-03-11T21:58:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/82/sqlc-gen-python/issues/82"}
| 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:51c7cb23-0330-65ad-b72f-30cdf0fe9b25 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C472:1A9FA2:36FBF4:4B9699:696E7126 |
| html-safe-nonce | 025c922c3b9e3c83584017bd604fc03f15873558ccd72fd3387a52466d21fc54 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDcyOjFBOUZBMjozNkZCRjQ6NEI5Njk5OjY5NkU3MTI2IiwidmlzaXRvcl9pZCI6Ijc2MjU1MDI4NjU3Mjc4NDQ2NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c16f001658bb96038cc117bbcbd02814a0bad3bc22aa5916441eb09c25b90675 |
| hovercard-subject-tag | issue:2911976071 |
| 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-gen-python/82/issue_layout |
| twitter:image | https://opengraph.githubassets.com/43f5172a892ec41b5da5219abe7b363638986f6100ccd6ceb4c178d8725bd3cb/sqlc-dev/sqlc-gen-python/issues/82 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/43f5172a892ec41b5da5219abe7b363638986f6100ccd6ceb4c178d8725bd3cb/sqlc-dev/sqlc-gen-python/issues/82 |
| og:image:alt | It would be really helpful to have the override functionality available in the go version of sqlc. In combination with the existing pydantic functionality, this would be very useful. e.g., currentl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | oliverlambson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01185010a96388a2a8cd8bd7f5824fdf090522b219f9aecf8c7ff1857aeb489b |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc-gen-python git https://github.com/sqlc-dev/sqlc-gen-python.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 548530161 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc-gen-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 548530161 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc-gen-python |
| 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 | 673a80c1bce2a1e6a48b530ce2b72bf8fd253386 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width