-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): Support subqueries in the FROM clause (#3227)
* fix(resolve): fix resolving reference to CTEs Fixed resolving refs to CTEs by adding CTEs to the aliasMap and indexing its columns when resolving catalog references. Fix #3219 * feat(compiler): Support subqueries in the FROM clause issue #2989, #2400 and probably others --------- Co-authored-by: Simon Klee <[email protected]>
- Loading branch information
Showing
11 changed files
with
290 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
https://github.com/sqlc-dev/sqlc/issues/3219 | ||
|
32 changes: 32 additions & 0 deletions
32
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/go/db.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/go/models.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/go/query.sql.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/query.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- name: CTERef :one | ||
WITH t1_ids AS ( | ||
SELECT id FROM t1 | ||
) | ||
SELECT * FROM t1_ids WHERE t1_ids.id = sqlc.arg('id'); | ||
|
||
-- name: CTEMultipleRefs :one | ||
WITH t1_ids AS ( | ||
SELECT id FROM t1 WHERE t1.id = sqlc.arg('id') | ||
), | ||
t2_ids AS ( | ||
SELECT id FROM t2 WHERE t2.id = sqlc.arg('id') | ||
), | ||
all_ids AS ( | ||
SELECT * FROM t1_ids | ||
UNION | ||
SELECT * FROM t2_ids | ||
) | ||
SELECT * FROM all_ids AS ids WHERE ids.id = sqlc.arg('id'); | ||
|
||
|
9 changes: 9 additions & 0 deletions
9
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE t1 | ||
( | ||
id SERIAL NOT NULL PRIMARY KEY | ||
); | ||
|
||
CREATE TABLE t2 | ||
( | ||
id SERIAL NOT NULL PRIMARY KEY | ||
); |
10 changes: 10 additions & 0 deletions
10
internal/endtoend/testdata/cte_resolve_ref/postgresql/pgx/sqlc.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: "2" | ||
sql: | ||
- engine: "postgresql" | ||
schema: "schema.sql" | ||
queries: "query.sql" | ||
gen: | ||
go: | ||
package: "querytest" | ||
out: "go" | ||
sql_package: "pgx/v5" |
54 changes: 54 additions & 0 deletions
54
internal/endtoend/testdata/join_alias/mysql/go/query.sql.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters