dolthub / dolthub/doltgresql

Support returning row sets from functions

Open
#638 1 comment 0 reactions 1 assignee Claimed by @jennifersp View on GitHub
enhancement
Dominant language
Go
Stars
2.1k
Forks
73
Avg merge
1d 10h
Merged PRs (30d)
129

Description

There are some functions (like [`unnest`](https://www.postgresql.org/docs/15/functions-array.html#:~:text=%E2%86%92%20%7B1%2C2%2C3%2C4%7D-,unnest,-(%20anyarray%20)%20%E2%86%92)) that should return a set of elements. We currently do not support returning sets of elements with our current function framework. For example, the [`unnest` function](https://github.com/dolthub/doltgresql/blob/main/server/functions/unnest.go) should return a set of `AnyElement`

```go
// unnest represents the PostgreSQL function of the same name, taking the same parameters.
var unnest = framework.Function1{
Name: "unnest",
Return: pgtypes.AnyElement, // TODO: Should return setof AnyElement
Parameters: [1]pgtypes.DoltgresType{pgtypes.AnyArray},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
valArr := val1.([]interface{})
if len(valArr) == 0 {
return nil, nil
}
if len(valArr) == 1 {
return valArr[0], nil
}
return nil, fmt.Errorf("unnest() only supports single-element arrays")
},
}
```

There are skipped tests for `unnest` [here](https://github.com/dolthub/doltgresql/blob/main/testing/go/functions_test.go#L888)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.