Skip to content

Commit 8cde4ef

Browse files
authored
catalog: Improve variadic argument support (#804)
1 parent 819b8b9 commit 8cde4ef

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build test test-examples regen
1+
.PHONY: build test test-examples regen start psql mysqlsh
22

33
build:
44
go build ./...
@@ -17,3 +17,12 @@ sqlc-dev:
1717

1818
sqlc-pg-gen:
1919
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen
20+
21+
start:
22+
docker-compose up -d
23+
24+
psql:
25+
PGPASSWORD=mysecretpassword psql --host=127.0.0.1 --port=5432 --username=postgres dinotest
26+
27+
mysqlsh:
28+
mysqlsh --sql --user root --password mysecretpassword --database dinotest 127.0.0.1:3306

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

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_build/query.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
-- name: SelectJSONBuildObject :one
22
SELECT
3+
json_build_object(),
34
json_build_object('foo'),
45
json_build_object('foo', 1),
56
json_build_object('foo', 1, 2),
67
json_build_object('foo', 1, 2, 'bar');
78

89
-- name: SelectJSONBuildArray :one
910
SELECT
11+
json_build_array(),
1012
json_build_array(1),
1113
json_build_array(1, 2),
1214
json_build_array(1, 2, 'foo'),

internal/engine/postgresql/pg_catalog.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/catalog/catalog.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ type Argument struct {
251251
Name string
252252
Type *ast.TypeName
253253
HasDefault bool
254-
Variadic bool
255254
Mode ast.FuncParamMode
256255
}
257256

internal/sql/catalog/public.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ func (c *Catalog) ResolveFuncCall(call *ast.FuncCall) (*Function, error) {
7272
if arg.HasDefault {
7373
defaults += 1
7474
}
75-
if arg.Variadic {
75+
if arg.Mode == ast.FuncParamVariadic {
7676
variadic = true
77+
defaults += 1
7778
}
7879
if arg.Name != "" {
7980
known[arg.Name] = struct{}{}
8081
}
8182
}
8283

8384
if variadic {
84-
// For now, assume variadic fucntions can't also have defaults
85-
if (len(named) + len(positional)) < len(args) {
85+
if (len(named) + len(positional)) < (len(args) - defaults) {
8686
continue
8787
}
8888
} else {

0 commit comments

Comments
 (0)