Title: Joined table variable names should include source table name for disambiguation · Issue #560 · sqlc-dev/sqlc · GitHub
Open Graph Title: Joined table variable names should include source table name for disambiguation · Issue #560 · sqlc-dev/sqlc
X Title: Joined table variable names should include source table name for disambiguation · Issue #560 · sqlc-dev/sqlc
Description: Hi, great library! When using an SQL JOIN statement, we can end up with tables that have the same column name in the same variable interpolation. Currently, this results in names such as Name and Name_2. For example, given the following ...
Open Graph Description: Hi, great library! When using an SQL JOIN statement, we can end up with tables that have the same column name in the same variable interpolation. Currently, this results in names such as Name and N...
X Description: Hi, great library! When using an SQL JOIN statement, we can end up with tables that have the same column name in the same variable interpolation. Currently, this results in names such as Name and N...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/560
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Joined table variable names should include source table name for disambiguation","articleBody":"Hi, great library!\r\n\r\nWhen using an SQL JOIN statement, we can end up with tables that have the same column name in the same variable interpolation. Currently, this results in names such as `Name` and `Name_2`. For example, given the following schema:\r\n\r\n```sql\r\nCREATE EXTENSION IF NOT EXISTS pgcrypto;\r\n\r\nCREATE TABLE users (\r\n id UUID gen_random_uuid (),\r\n name TEXT\r\n)\r\n\r\nCREATE TABLE posts (\r\n id UUID gen_random_uuid (),\r\n user_id UUID REFERENCES users (id),\r\n name TEXT\r\n)\r\n```\r\n\r\nAnd the following query:\r\n```sql\r\n-- name: GetPostsByUserByName :one\r\nSELECT * FROM posts\r\nLEFT JOIN users ON posts.user_id = users.id\r\nWHERE posts.name = $1 AND users.name = $2\r\n```\r\n\r\nWe end up with the following parameter type:\r\n```go\r\ntype GetPostsByUserByNameParams struct {\r\n\tName uuid.UUID\r\n\tName_2 uuid.UUID\r\n}\r\n```\r\n\r\nThis is obviously not ideal, and I think we should do what SQL does for disambiguation; use the table names. It could look something like this (using the existing algorithm for de-pluralising table names):\r\n\r\n```go\r\ntype GetPostsByUserByNameParams struct {\r\n\tPostName uuid.UUID\r\n\tUserName uuid.UUID\r\n}\r\n```\r\n\r\nAlternatively, if that is too heavy handed, I tried using the `rename` functionality to override the variable name, but it doesn't seem to work as expected; the following accomplished nothing:\r\n\r\n```yaml\r\nrename:\r\n posts.name: \"PostName\"\r\n users.name: \"UserName\"\r\n```\r\n\r\nAny thoughts appreciated!","author":{"url":"https://github.com/johanbrandhorst","@type":"Person","name":"johanbrandhorst"},"datePublished":"2020-06-22T17:02:45Z","url":"https://github.com/sqlc-dev/sqlc/issues/560"}
| 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:72d9e949-6340-5ec1-d112-6df60c0380b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0B8:2D02CB:4DD136:66B13B:6B0178B3 |
| html-safe-nonce | 5dc2c0188c0ce375487245bbe5b5c0da7c3274266e6ded9d1ff9c2f7fd76c04e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEI4OjJEMDJDQjo0REQxMzY6NjZCMTNCOjZCMDE3OEIzIiwidmlzaXRvcl9pZCI6IjIwMzEzOTU3MjE3ODEwMTY3NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2e9874144dbf432bcf31f8d2adfe4b96cc9d5fa0d9f0aa80506ffbf2070e3856 |
| hovercard-subject-tag | issue:643229151 |
| 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/560/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a995e4b4a0910e8549d247e2c6fddbc7a44a7364fa0af393ec40e375889f8e3/sqlc-dev/sqlc/issues/560 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a995e4b4a0910e8549d247e2c6fddbc7a44a7364fa0af393ec40e375889f8e3/sqlc-dev/sqlc/issues/560 |
| og:image:alt | Hi, great library! When using an SQL JOIN statement, we can end up with tables that have the same column name in the same variable interpolation. Currently, this results in names such as Name and N... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johanbrandhorst |
| 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