diff --git a/internal/catalog/build.go b/internal/catalog/build.go index 85d51c309c..38606647cb 100644 --- a/internal/catalog/build.go +++ b/internal/catalog/build.go @@ -353,8 +353,12 @@ func Update(c *pg.Catalog, stmt nodes.Node) error { args := make([]pg.Argument, arity) for i, item := range n.Parameters.Items { arg := item.(nodes.FunctionParameter) + var name string + if arg.Name != nil { + name = *arg.Name + } args[i] = pg.Argument{ - Name: *arg.Name, + Name: name, DataType: join(arg.ArgType.Names, "."), HasDefault: arg.Defexpr != nil, } diff --git a/internal/catalog/build_test.go b/internal/catalog/build_test.go index cb1872dff5..76416eca4b 100644 --- a/internal/catalog/build_test.go +++ b/internal/catalog/build_test.go @@ -322,6 +322,13 @@ func TestUpdate(t *testing.T) { `, pg.NewCatalog(), }, + { + ` + DROP FUNCTION IF EXISTS bar(text); + DROP FUNCTION IF EXISTS bar(text) CASCADE; + `, + pg.NewCatalog(), + }, { ` CREATE TABLE venues (id SERIAL PRIMARY KEY); @@ -343,6 +350,31 @@ func TestUpdate(t *testing.T) { }, }, }, + { // first argument has no name + ` + CREATE FUNCTION foo(TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql; + `, + pg.Catalog{ + Schemas: map[string]pg.Schema{ + "public": { + Funcs: map[string][]pg.Function{ + "foo": []pg.Function{ + { + Name: "foo", + Arguments: []pg.Argument{ + { + Name: "", + DataType: "text", + }, + }, + ReturnType: "bool", + }, + }, + }, + }, + }, + }, + }, { // same name, different arity ` CREATE FUNCTION foo(bar TEXT) RETURNS bool AS $$ SELECT true $$ LANGUAGE sql;