Skip to content

Conversation

@kitagry
Copy link

@kitagry kitagry commented Jan 27, 2026

Fixed incorrect nullability inference when using subqueries with LEFT/RIGHT/FULL OUTER JOINs.

When using subqueries in JOINs like:
SELECT * FROM a LEFT JOIN (SELECT * FROM b) si ON si.a_id = a.id

Columns from subquery 'si' were incorrectly treated as NOT NULL.

Root cause: The isTableRequired() function did not handle *ast.RangeSubselect (subquery ranges).

Solution:

  • Added *ast.RangeSubselect case to isTableRequired()
  • Match subqueries by their alias names
  • Verified all JOIN types (LEFT/RIGHT/FULL OUTER) work correctly

Test coverage:

  • Added internal/endtoend/testdata/join_left_subquery/postgresql/
  • Covers LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN patterns

Fixes #4117

Fixed incorrect nullability inference when using subqueries with LEFT/RIGHT/FULL OUTER JOINs.

When using subqueries in JOINs like:
  SELECT * FROM a LEFT JOIN (SELECT * FROM b) si ON si.a_id = a.id

Columns from subquery 'si' were incorrectly treated as NOT NULL.

Root cause: The isTableRequired() function did not handle *ast.RangeSubselect (subquery ranges).

Solution:
- Added *ast.RangeSubselect case to isTableRequired()
- Match subqueries by their alias names
- Verified all JOIN types (LEFT/RIGHT/FULL OUTER) work correctly

Test coverage:
- Added internal/endtoend/testdata/join_left_subquery/postgresql/
- Covers LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN patterns

Fixes sqlc-dev#4117
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang labels Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen not producing nullable output values when using LEFT Joins and subqueries (GO)

1 participant