Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Retrieve Larg/Rarg join query after inner join #2051

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ func isTableRequired(n ast.Node, col *Column, prior int) int {
return helper(tableOptional, tableRequired)
case ast.JoinTypeFull:
return helper(tableOptional, tableOptional)
case ast.JoinTypeInner:
return helper(tableRequired, tableRequired)
}
case *ast.List:
for _, item := range n.Items {
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/join_clauses_order/postgresql/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions internal/endtoend/testdata/join_clauses_order/postgresql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CREATE TABLE a (
id BIGSERIAL PRIMARY KEY,
a TEXT NOT NULL
);

CREATE TABLE b (
id BIGSERIAL PRIMARY KEY,
b TEXT NOT NULL,
a_id BIGINT NOT NULL REFERENCES a (id)
);

CREATE TABLE c (
id BIGSERIAL PRIMARY KEY,
c TEXT NOT NULL,
a_id BIGINT NOT NULL REFERENCES a (id)
);

CREATE TABLE d (
id BIGSERIAL PRIMARY KEY,
d TEXT NOT NULL,
a_id BIGINT NOT NULL REFERENCES a (id)
);

CREATE TABLE e (
id BIGSERIAL PRIMARY KEY,
e TEXT NOT NULL,
a_id BIGINT NOT NULL REFERENCES a (id)
);

-- name: TestLeftInner :many
SELECT a.a, b.b, c.c
FROM a
LEFT JOIN b ON b.a_id = a.id
INNER JOIN c ON c.a_id = a.id;

-- name: TestInnerLeft :many
SELECT a.a, b.b, c.c
FROM a
INNER JOIN b ON b.a_id = a.id
LEFT JOIN c ON c.a_id = a.id;

-- name: TestLeftInnerLeftInner :many
SELECT a.a, b.b, c.c, d.d, e.e
FROM a
LEFT JOIN b ON b.a_id = a.id
INNER JOIN c ON c.a_id = a.id
LEFT JOIN d ON d.a_id = a.id
INNER JOIN e ON e.a_id = a.id;

-- name: TestInnerLeftInnerLeft :many
SELECT a.a, b.b, c.c, d.d, e.e
FROM a
INNER JOIN b ON b.a_id = a.id
LEFT JOIN c ON c.a_id = a.id
INNER JOIN d ON d.a_id = a.id
LEFT JOIN e ON e.a_id = a.id;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/join_clauses_order/postgresql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}