Skip to content

Commit e0666b5

Browse files
compiler: temp fix for typecast function parameters (#530)
In cases where a FuncCall has a TypeCast node as an argument, resolveCatalogRefs would erroneously output two parameters for that argument instead of one. This fix eliminates the duplicate param and allows queries with typecast function args to compile, but it loses track of the argument's connection with the function called. This means the parameters use the generic ColumnN names even when the function has named parameters. A future refactor of resolveCatalogRefs to better address function calls will be necessary to address the name issue. (this only edits the experimental package and does not fix the old dinosql compiler) Closes #520 Co-authored-by: Kyle Conroy <kyle@conroy.org>
1 parent 8aa23ee commit e0666b5

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
lines changed

internal/compiler/resolve.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ func resolveCatalogRefs(c *catalog.Catalog, rvs []*pg.RangeVar, args []paramRef,
193193
if inode.Number != ref.ref.Number {
194194
continue
195195
}
196+
case *pg.TypeCast:
197+
pr, ok := inode.Arg.(*pg.ParamRef)
198+
if !ok {
199+
continue
200+
}
201+
if pr.Number != ref.ref.Number {
202+
continue
203+
}
196204
case *pg.NamedArgExpr:
197205
pr, ok := inode.Arg.(*pg.ParamRef)
198206
if !ok {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"experimental_parser_only": true
3+
}

internal/endtoend/testdata/func_args_typecast/go/db.go

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

internal/endtoend/testdata/func_args_typecast/go/models.go

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

internal/endtoend/testdata/func_args_typecast/go/query.sql.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE FUNCTION plus(a integer, b integer) RETURNS integer AS $$
2+
BEGIN
3+
RETURN a + b;
4+
END;
5+
$$ LANGUAGE plpgsql;
6+
7+
-- name: PlusPositionalCast :one
8+
SELECT plus($1, $2::INTEGER);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"name": "querytest",
7+
"schema": "query.sql",
8+
"queries": "query.sql"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)