cockroachdb / cockroachdb/cockroach

Support passing name/value pairs to functions

Open
#149,314 2 comments 0 reactions 0 assignees View on GitHub
A-sql-udf C-enhancement O-community T-sql-queries X-blathers-triaged
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Is your feature request related to a problem? Please describe.**

It appears there's currently no way to pass name/value pairs to functions, which is essential when working with functions that have defaulted parameters.

**Describe the solution you'd like**

With a function like this:

```sql
create function f_default(p1 integer = 0, p2 integer = 1)
returns integer
as
$$
begin
return p1 + p2;
end;
$$ language plpgsql;
```

It's important to be able to pass name/value pairs like this in PostgreSQL:

```sql
select f_default(p2 := 1);
select f_default(p2 => 1);
```

Both syntaxes are equivalent in PostgreSQL, as far as I can tell.

**Describe alternatives you've considered**

I could look up all defaults from the `information_schema`, and pass them explicitly:

```sql
select f_default(
(
select parameter_default::int
from information_schema.parameters
where specific_name like 'f_default_%'
and ordinal_position = 1
),
1
);
```

Jira issue: CRDB-52088

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.