You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Joined table variable names should include source table name for disambiguation #560
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 schema:
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATETABLEusers (
id UUID gen_random_uuid (),
name TEXT
)
CREATETABLEposts (
id UUID gen_random_uuid (),
user_id UUID REFERENCES users (id),
name TEXT
)
typeGetPostsByUserByNameParamsstruct {
Name uuid.UUIDName_2 uuid.UUID
}
This 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):
Alternatively, 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:
Activity
kyleconroy commentedon Jun 22, 2020
The renaming functionality is poorly documented. It actually doesn't work for parameters.
But I have a solution for you: named parameters. You can used either
sqlc.arg()or@.I do agree that we should be able to generate these better names automatically, but it's not something I'm focusing on right now.
johanbrandhorst commentedon Jun 22, 2020
Fantastic, thanks for the workaround!