cockroachdb / cockroachdb/cockroach

UNNEST on UDT array should flatten the UDT into the calling query

Open
#167,271 1 comment 0 reactions 0 assignees View on GitHub
C-bug O-community T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

In PostgreSQL, it is possible to use `UNNEST` on a UDT array. This flattens the UDT into the calling query:

**To Reproduce**

```sql
create type u as (x int, y int);

select t2.*
from
(values(array[row(1, 2)::u])) as t1 (a),
unnest(t1.a) as t2 (x, y);
```

**Expected behavior**

In PostgreSQL, this produces the unnested UDT:

```
|x |y |
|---|---|
|1 |2 |
```

In CockroachDB, this raises:

> SQL Error [42P10]: ERROR: source "t2" has 1 columns available but 2 columns specified

**Environment:**
- CockroachDB version: CockroachDB CCL v26.1.1 (x86_64-pc-linux-gnu, built 2026/03/04 12:08:22, go1.25.5)
- Server OS: Linux on Docker on Windows
- Client app: JDBC

Jira issue: CRDB-62363

Epic CRDB-60819

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided UNNEST query in CockroachDB and PostgreSQL, then trace the SQL execution path for arrays of user-defined types. Done means the CockroachDB query accepts the two-column alias and returns x=1 and y=2, matching PostgreSQL.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.