Skip to content

catalog: Improve variadic argument support #804

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
Nov 22, 2020
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
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test test-examples regen
.PHONY: build test test-examples regen start psql mysqlsh

build:
go build ./...
Expand All @@ -17,3 +17,12 @@ sqlc-dev:

sqlc-pg-gen:
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen

start:
docker-compose up -d

psql:
PGPASSWORD=mysecretpassword psql --host=127.0.0.1 --port=5432 --username=postgres dinotest

mysqlsh:
mysqlsh --sql --user root --password mysecretpassword --database dinotest 127.0.0.1:3306
6 changes: 6 additions & 0 deletions internal/endtoend/testdata/json_build/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/json_build/query.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
-- name: SelectJSONBuildObject :one
SELECT
json_build_object(),
json_build_object('foo'),
json_build_object('foo', 1),
json_build_object('foo', 1, 2),
json_build_object('foo', 1, 2, 'bar');

-- name: SelectJSONBuildArray :one
SELECT
json_build_array(),
json_build_array(1),
json_build_array(1, 2),
json_build_array(1, 2, 'foo'),
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/postgresql/pg_catalog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/sql/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ type Argument struct {
Name string
Type *ast.TypeName
HasDefault bool
Variadic bool
Mode ast.FuncParamMode
}

Expand Down
6 changes: 3 additions & 3 deletions internal/sql/catalog/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ func (c *Catalog) ResolveFuncCall(call *ast.FuncCall) (*Function, error) {
if arg.HasDefault {
defaults += 1
}
if arg.Variadic {
if arg.Mode == ast.FuncParamVariadic {
variadic = true
defaults += 1
}
if arg.Name != "" {
known[arg.Name] = struct{}{}
}
}

if variadic {
// For now, assume variadic fucntions can't also have defaults
if (len(named) + len(positional)) < len(args) {
if (len(named) + len(positional)) < (len(args) - defaults) {
continue
}
} else {
Expand Down