Skip to content

internal/catalog: Parse unnamed function arguments #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/catalog/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
32 changes: 32 additions & 0 deletions internal/catalog/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down