diff --git a/internal/compiler/resolve.go b/internal/compiler/resolve.go index 547effc9e0..02e3c4c7a5 100644 --- a/internal/compiler/resolve.go +++ b/internal/compiler/resolve.go @@ -255,10 +255,6 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, } } - number := 0 - if pr, ok := n.Left.(*ast.ParamRef); ok { - number = pr.Number - } for _, table := range tables { schema := table.Schema @@ -269,10 +265,19 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, if c, ok := typeMap[schema][table.Name][key]; ok { defaultP := named.NewInferredParam(key, c.IsNotNull) p, isNamed := params.FetchMerge(ref.ref.Number, defaultP) + var namePrefix string + if !isNamed { + if ref.ref == n.Left { + namePrefix = "from_" + } else if ref.ref == n.Right { + namePrefix = "to_" + } + } + a = append(a, Parameter{ - Number: number, + Number: ref.ref.Number, Column: &Column{ - Name: p.Name(), + Name: namePrefix + p.Name(), DataType: dataType(&c.Type), NotNull: p.NotNull(), Unsigned: c.IsUnsigned, diff --git a/internal/endtoend/testdata/between_args/mysql/go/query.sql.go b/internal/endtoend/testdata/between_args/mysql/go/query.sql.go index cd792fbb3d..a4c2221847 100644 --- a/internal/endtoend/testdata/between_args/mysql/go/query.sql.go +++ b/internal/endtoend/testdata/between_args/mysql/go/query.sql.go @@ -16,12 +16,12 @@ WHERE price BETWEEN ? AND ? ` type GetBetweenPricesParams struct { - Price int32 - Price_2 int32 + FromPrice int32 + ToPrice int32 } func (q *Queries) GetBetweenPrices(ctx context.Context, arg GetBetweenPricesParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPrices, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPrices, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err } @@ -50,12 +50,12 @@ WHERE products.price BETWEEN ? AND ? ` type GetBetweenPricesTableParams struct { - Price int32 - Price_2 int32 + FromPrice int32 + ToPrice int32 } func (q *Queries) GetBetweenPricesTable(ctx context.Context, arg GetBetweenPricesTableParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPricesTable, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPricesTable, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err } @@ -84,12 +84,12 @@ WHERE p.price BETWEEN ? AND ? ` type GetBetweenPricesTableAliasParams struct { - Price int32 - Price_2 int32 + FromPrice int32 + ToPrice int32 } func (q *Queries) GetBetweenPricesTableAlias(ctx context.Context, arg GetBetweenPricesTableAliasParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPricesTableAlias, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPricesTableAlias, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err } diff --git a/internal/endtoend/testdata/between_args/sqlite/go/query.sql.go b/internal/endtoend/testdata/between_args/sqlite/go/query.sql.go index 19aa939f9e..9f0531f660 100644 --- a/internal/endtoend/testdata/between_args/sqlite/go/query.sql.go +++ b/internal/endtoend/testdata/between_args/sqlite/go/query.sql.go @@ -16,12 +16,12 @@ WHERE price BETWEEN ? AND ? ` type GetBetweenPricesParams struct { - Price int64 - Price_2 int64 + FromPrice int64 + ToPrice int64 } func (q *Queries) GetBetweenPrices(ctx context.Context, arg GetBetweenPricesParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPrices, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPrices, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err } @@ -50,12 +50,12 @@ WHERE products.price BETWEEN ? AND ? ` type GetBetweenPricesTableParams struct { - Price int64 - Price_2 int64 + FromPrice int64 + ToPrice int64 } func (q *Queries) GetBetweenPricesTable(ctx context.Context, arg GetBetweenPricesTableParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPricesTable, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPricesTable, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err } @@ -84,12 +84,12 @@ WHERE p.price BETWEEN ? AND ? ` type GetBetweenPricesTableAliasParams struct { - Price int64 - Price_2 int64 + FromPrice int64 + ToPrice int64 } func (q *Queries) GetBetweenPricesTableAlias(ctx context.Context, arg GetBetweenPricesTableAliasParams) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getBetweenPricesTableAlias, arg.Price, arg.Price_2) + rows, err := q.db.QueryContext(ctx, getBetweenPricesTableAlias, arg.FromPrice, arg.ToPrice) if err != nil { return nil, err }