Skip to content

Commit 1b74ac5

Browse files
authored
fix: Retrieve Larg/Rarg join query after inner join (#2051)
1 parent 186862c commit 1b74ac5

File tree

6 files changed

+312
-0
lines changed

6 files changed

+312
-0
lines changed

internal/compiler/output_columns.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ func isTableRequired(n ast.Node, col *Column, prior int) int {
347347
return helper(tableOptional, tableRequired)
348348
case ast.JoinTypeFull:
349349
return helper(tableOptional, tableOptional)
350+
case ast.JoinTypeInner:
351+
return helper(tableRequired, tableRequired)
350352
}
351353
case *ast.List:
352354
for _, item := range n.Items {

internal/endtoend/testdata/join_clauses_order/postgresql/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_clauses_order/postgresql/go/models.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/join_clauses_order/postgresql/go/query.sql.go

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CREATE TABLE a (
2+
id BIGSERIAL PRIMARY KEY,
3+
a TEXT NOT NULL
4+
);
5+
6+
CREATE TABLE b (
7+
id BIGSERIAL PRIMARY KEY,
8+
b TEXT NOT NULL,
9+
a_id BIGINT NOT NULL REFERENCES a (id)
10+
);
11+
12+
CREATE TABLE c (
13+
id BIGSERIAL PRIMARY KEY,
14+
c TEXT NOT NULL,
15+
a_id BIGINT NOT NULL REFERENCES a (id)
16+
);
17+
18+
CREATE TABLE d (
19+
id BIGSERIAL PRIMARY KEY,
20+
d TEXT NOT NULL,
21+
a_id BIGINT NOT NULL REFERENCES a (id)
22+
);
23+
24+
CREATE TABLE e (
25+
id BIGSERIAL PRIMARY KEY,
26+
e TEXT NOT NULL,
27+
a_id BIGINT NOT NULL REFERENCES a (id)
28+
);
29+
30+
-- name: TestLeftInner :many
31+
SELECT a.a, b.b, c.c
32+
FROM a
33+
LEFT JOIN b ON b.a_id = a.id
34+
INNER JOIN c ON c.a_id = a.id;
35+
36+
-- name: TestInnerLeft :many
37+
SELECT a.a, b.b, c.c
38+
FROM a
39+
INNER JOIN b ON b.a_id = a.id
40+
LEFT JOIN c ON c.a_id = a.id;
41+
42+
-- name: TestLeftInnerLeftInner :many
43+
SELECT a.a, b.b, c.c, d.d, e.e
44+
FROM a
45+
LEFT JOIN b ON b.a_id = a.id
46+
INNER JOIN c ON c.a_id = a.id
47+
LEFT JOIN d ON d.a_id = a.id
48+
INNER JOIN e ON e.a_id = a.id;
49+
50+
-- name: TestInnerLeftInnerLeft :many
51+
SELECT a.a, b.b, c.c, d.d, e.e
52+
FROM a
53+
INNER JOIN b ON b.a_id = a.id
54+
LEFT JOIN c ON c.a_id = a.id
55+
INNER JOIN d ON d.a_id = a.id
56+
LEFT JOIN e ON e.a_id = a.id;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"engine": "postgresql",
7+
"name": "querytest",
8+
"schema": "query.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)