Skip to content

Commit a7d4d9c

Browse files
authored
fix(compiler): No panic on full-qualified column names (#2956)
1 parent ed9264d commit a7d4d9c

File tree

8 files changed

+184
-0
lines changed

8 files changed

+184
-0
lines changed

internal/compiler/resolve.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
173173
case 2:
174174
alias = items[0]
175175
key = items[1]
176+
case 3:
177+
// schema := items[0]
178+
alias = items[1]
179+
key = items[2]
176180
default:
177181
panic("too many field items: " + strconv.Itoa(len(items)))
178182
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/sqlc-dev/sqlc/issues/2948

internal/endtoend/testdata/schema_table_column_ref/postgresql/pgx/go/db.go

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

internal/endtoend/testdata/schema_table_column_ref/postgresql/pgx/go/models.go

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

internal/endtoend/testdata/schema_table_column_ref/postgresql/pgx/go/query.sql.go

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- name: GetTotalSlackQueries :one
2+
SELECT
3+
COUNT(*) AS count
4+
FROM astoria.slack_feedback
5+
WHERE astoria.slack_feedback.workspace_id = $1
6+
AND created_at BETWEEN $2::date AND $3::date;
7+
8+
-- name: GetTotalSlackQueriesResolved :one
9+
SELECT
10+
COUNT(*) AS count
11+
FROM astoria.slack_feedback
12+
WHERE astoria.slack_feedback.workspace_id = $1
13+
AND (issue_raised = false OR issue_raised IS NULL)
14+
AND created_at BETWEEN $2::date AND $3::date;
15+
16+
-- name: GetTotalSlackQueriesRequestsCreated :one
17+
SELECT
18+
COUNT(*) AS count
19+
FROM astoria.tickets
20+
WHERE astoria.tickets.workspace_id = $1
21+
AND source = 'RAISED_FROM_BOT'
22+
AND created_at BETWEEN $2::date AND $3::date;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE SCHEMA astoria;
2+
3+
CREATE TABLE astoria.slack_feedback (
4+
id BIGSERIAL PRIMARY KEY,
5+
workspace_id BIGINT NOT NULL,
6+
created_at TIMESTAMP NOT NULL,
7+
issue_raised BOOLEAN
8+
);
9+
10+
CREATE TABLE astoria.tickets (
11+
id BIGSERIAL PRIMARY KEY,
12+
workspace_id BIGINT NOT NULL,
13+
created_at TIMESTAMP NOT NULL,
14+
source text NOT NULL
15+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "2"
2+
sql:
3+
- engine: "postgresql"
4+
schema: "schema.sql"
5+
queries: "query.sql"
6+
gen:
7+
go:
8+
package: "querytest"
9+
out: "go"
10+
sql_package: "pgx/v5"

0 commit comments

Comments
 (0)