Skip to content

Commit ad041d0

Browse files
authored
Skip over unknown functions in source tables (#1017)
1 parent 422d120 commit ad041d0

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

internal/compiler/output_columns.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,24 @@ func sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, error) {
299299
var tables []*Table
300300
for _, item := range list.Items {
301301
switch n := item.(type) {
302+
302303
case *ast.FuncName:
304+
// If the function or table can't be found, don't error out. There
305+
// are many queries that depend on functions unknown to sqlc.
303306
fn, err := qc.GetFunc(n)
304307
if err != nil {
305-
return nil, err
308+
continue
306309
}
307310
table, err := qc.GetTable(&ast.TableName{
308311
Catalog: fn.ReturnType.Catalog,
309312
Schema: fn.ReturnType.Schema,
310313
Name: fn.ReturnType.Name,
311314
})
312315
if err != nil {
313-
return nil, err
316+
continue
314317
}
315318
tables = append(tables, table)
319+
316320
case *ast.RangeSubselect:
317321
cols, err := outputColumns(qc, n.Subquery)
318322
if err != nil {
@@ -345,6 +349,7 @@ func sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, error) {
345349
}
346350
}
347351
tables = append(tables, table)
352+
348353
default:
349354
return nil, fmt.Errorf("sourceTable: unsupported list item type: %T", n)
350355
}

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

Lines changed: 35 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/query.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
SELECT *
33
FROM users_func()
44
WHERE first_name != '';
5+
6+
/* name: GenerateSeries :many */
7+
SELECT ($1::inet) + i
8+
FROM generate_series(0, $2::int) AS i
9+
LIMIT 1;

0 commit comments

Comments
 (0)