Skip to content

Commit adaabbd

Browse files
fixprevent panics when encountering unexpected ast nodes in range function lists (#2449)
1 parent 6051c03 commit adaabbd

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

internal/compiler/output_columns.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,25 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
503503
switch n := item.(type) {
504504

505505
case *ast.RangeFunction:
506-
// If the function or table can't be found, don't error out. There
507-
// are many queries that depend on functions unknown to sqlc.
508506
var funcCall *ast.FuncCall
509507
switch f := n.Functions.Items[0].(type) {
510508
case *ast.List:
511-
funcCall = f.Items[0].(*ast.FuncCall)
509+
switch fi := f.Items[0].(type) {
510+
case *ast.FuncCall:
511+
funcCall = fi
512+
case *ast.SQLValueFunction:
513+
continue // TODO handle this correctly
514+
default:
515+
continue
516+
}
512517
case *ast.FuncCall:
513518
funcCall = f
514519
default:
515520
return nil, fmt.Errorf("sourceTables: unsupported function call type %T", n.Functions.Items[0])
516521
}
517522

523+
// If the function or table can't be found, don't error out. There
524+
// are many queries that depend on functions unknown to sqlc.
518525
fn, err := qc.GetFunc(funcCall.Func)
519526
if err != nil {
520527
continue

internal/endtoend/testdata/func_return/postgresql/pgx/v4/go/query.sql.go

Lines changed: 14 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_return/postgresql/pgx/v4/query.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ WHERE first_name != '';
77
/* name: GenerateSeries :many */
88
SELECT ($1::inet) + i
99
FROM generate_series(0, $2::int) AS i
10-
LIMIT 1;
10+
LIMIT 1;
11+
12+
/* name: GetDate :one */
13+
SELECT * from CURRENT_DATE;

internal/endtoend/testdata/func_return/postgresql/pgx/v5/go/query.sql.go

Lines changed: 14 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_return/postgresql/pgx/v5/query.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ WHERE first_name != '';
77
/* name: GenerateSeries :many */
88
SELECT ($1::inet) + i
99
FROM generate_series(0, $2::int) AS i
10-
LIMIT 1;
10+
LIMIT 1;
11+
12+
/* name: GetDate :one */
13+
SELECT * from CURRENT_DATE;

internal/endtoend/testdata/func_return/postgresql/stdlib/go/query.sql.go

Lines changed: 14 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_return/postgresql/stdlib/query.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ WHERE first_name != '';
77
/* name: GenerateSeries :many */
88
SELECT ($1::inet) + i
99
FROM generate_series(0, $2::int) AS i
10-
LIMIT 1;
10+
LIMIT 1;
11+
12+
/* name: GetDate :one */
13+
SELECT * from CURRENT_DATE;

0 commit comments

Comments
 (0)