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
Codegen not producing nullable output values when using LEFT Joins and subqueries (GO) #4117
Hello, the problem i stumbled on is the follwoing.
If i want to use sqlc for queries that are Joining Subqueries with left joins and the output is not generated as nullable.
If i now use this query
-- name: TEST :manySELECT*FROM a AS table_a
LEFT JOIN (SELECT*FROM b WHEREb.nameis not null) si ONsi.a_id=table_a.id;
The output is this:
typeTESTRowstruct {
ID uuid.UUIDName pgtype.TextID_2 uuid.UUIDAID uuid.UUIDName_2 pgtype.Text
}
As you can see. The Properties (IDs) from table b are uuid.UUID and not pointers or other nullable values. This is not working and will produce errors during scanning.
If the LEFT JOIN is done without a subquery it works as expected:
The following query:
-- name: TEST2 :manySELECT*FROM a AS table_a
LEFT JOIN b AS table_b ONtable_b.a_id=table_a.idWHEREtable_b.nameis not null;
Is generting this output:
typeTEST2Rowstruct {
ID uuid.UUIDName pgtype.TextID_2*uuid.UUIDAID*uuid.UUIDName_2 pgtype.Text
}
I assume this Problem can also be reproduced with right joins.
Relevant log output
Database schema
Schema:
CREATETABLEa (
id uuid PRIMARY KEY,
name TEXT
);
CREATETABLEb (
id uuid PRIMARY KEY,
a_id uuid NOT NULLREFERENCES a (id),
name TEXT
);
Activity
fix(compiler): handle subqueries in JOIN nullability inference