cockroachdb / cockroachdb/cockroach

Support WITH ORDINALITY also on VALUES clause

Open
#93,704 5 comments 0 reactions 0 assignees View on GitHub
C-enhancement O-community T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the solution you'd like**

I've noticed that I can place `WITH ORDINALITY` almost anywhere on a table expression:
https://www.cockroachlabs.com/docs/stable/table-expressions.html

image

It even works for standalone [`table_clause`](https://www.cockroachlabs.com/docs/stable/sql-grammar.html#table_clause):

```sql
create view v as select 'a' a;
table v with ordinality;
```

Producing:

```
|a |ordinality|
|---|----------|
|a |1 |
```

Or also:

```sql
select * from (table v with ordinality);
```

But it doesn't work for the standalone [`values_clause`](https://www.cockroachlabs.com/docs/stable/sql-grammar.html#values_clause):

I.e. this doesn't work:

```sql
values ('a') with ordinality;
```

I have to do this, instead:

```sql
select * from (values ('a')) with ordinality;
```

I wonder if this is just an oversight? It's probably rarely useful, but seems to be a reasonable change from a consistency perspective?

**Additional context**

As a side note, I wonder if this improved `WITH ORDINALITY` support is worth mentioning here: https://www.cockroachlabs.com/docs/stable/postgresql-compatibility.html

Jira issue: CRDB-22489

Epic CRDB-60820

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.