cockroachdb / cockroachdb/cockroach

sql: using `$1.field_name` syntax in UDFs fails with an error

Open
#99,725 0 comments 0 reactions 0 assignees View on GitHub
A-sql-routine C-bug O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

I cannot use the `$1.field_name` syntax to select columns from composite types passed to UDFs.

**To Reproduce**

On cockroach demo, run the following:
```
CREATE TABLE emp (name TEXT, salary INT);

CREATE FUNCTION double_salary(emp) RETURNS numeric AS $$
SELECT $1.salary * 2 AS salary;
$$ LANGUAGE SQL;
```
This succeeds on Postgres, but on CRDB it fails with the error:
```
ERROR: at or near ".": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
SELECT $1.salary * 2 AS salary
^
```

**Expected behavior**

Using `$1.field_name` syntax should succeed.

**Environment:**
- CockroachDB version: master (i.e. 23.1 alpha)
- Server OS: MacOS Ventura (Apple M1 Pro)
- Client app: cockroach demo

Jira issue: CRDB-26040

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.