Skip to content

fix(compiler): Fix between expression handling of table references #1268

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/compiler/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ func resolveCatalogRefs(c *catalog.Catalog, qc *QueryCatalog, rvs []*ast.RangeVa

var key string
if ref, ok := n.Expr.(*ast.ColumnRef); ok {
if str, ok := ref.Fields.Items[0].(*ast.String); ok {
itemsCount := len(ref.Fields.Items)
if str, ok := ref.Fields.Items[itemsCount-1].(*ast.String); ok {
key = str.Str
}
}
Expand Down
68 changes: 68 additions & 0 deletions internal/endtoend/testdata/between_args/mysql/go/query.sql.go

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

10 changes: 10 additions & 0 deletions internal/endtoend/testdata/between_args/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ CREATE TABLE products (
SELECT *
FROM products
WHERE price BETWEEN ? AND ?;

-- name: GetBetweenPricesTable :many
SELECT *
FROM products
WHERE products.price BETWEEN ? AND ?;

-- name: GetBetweenPricesTableAlias :many
SELECT *
FROM products as p
WHERE p.price BETWEEN ? AND ?;
14 changes: 7 additions & 7 deletions internal/endtoend/testdata/between_args/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
{
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}