cockroachdb / cockroachdb/cockroach

postgresql 18 compatibility: support `OLD`/`NEW` syntax in `RETURNING` clause for modified rows

Closed
#160,182 3 comments 1 reaction 1 assignee Claimed by @BryanWangAtCRL View on GitHub
A-sql-pgcompat C-enhancement E-starter O-community T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

This is a feature [recently added in PostgreSQL 18](https://www.postgresql.org/docs/18/dml-returning.html
).

Simple example:
```sql
UPDATE products SET price = price * 1.10
WHERE price <= 99.99
RETURNING name, old.price AS old_price, new.price AS new_price,
new.price - old.price AS price_change;
```

**Is your feature request related to a problem? Please describe.**
My usecase makes heavy use of computed expressions in returning clauses with a large number of nodes, and I've run into the case where I need to compare with older data (especially when updating rows).

**Describe alternatives you've considered**
Subqueries, fetching the data beforehand in a serializable transaction. These both come with downsides, seems pretty clear.

Jira issue: CRDB-58213

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.