cockroachdb / cockroachdb/cockroach

sql: support column definition list with no data source alias

Open
#149,706 0 comments 0 reactions 0 assignees View on GitHub
A-sql-routine C-enhancement O-pg-regress T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

When a record-returning routine is used as a data source in a query, it must be given a column definition list to indicate the expected column types:
```
root@localhost:26257/defaultdb> create function f() returns record language sql as $$ select 1, 2 $$;
CREATE FUNCTION

Time: 44ms total (execution 24ms / network 21ms)

root@localhost:26257/defaultdb> select * from f();
ERROR: a column definition list is required for functions returning "record"
SQLSTATE: 42601
root@localhost:26257/defaultdb> select * from f() as foo (x int, y int);
x | y
----+----
1 | 2
(1 row)

Time: 3ms total (execution 2ms / network 0ms)
```
It is also valid to omit the alias for the data source, but we currently do not allow it:
```
root@localhost:26257/defaultdb> select * from f() as (x int, y int);
ERROR: a column definition list is required for functions returning "record"
SQLSTATE: 42601
```
This issue tracks adding support for a column definition list with no data-source alias.

Jira issue: CRDB-52293

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two SQL examples in the issue and compare the aliased and alias-free forms. Done means a record-returning function accepts `as (x int, y int)` without a data-source alias and returns the declared columns and values, while the existing aliased form continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.