cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.92k stars 3.78k forks source link

sql: provide mechanisnm to determine whether an UPSERT did an UPDATE or INSERT #50418

Open ajwerner opened 4 years ago

ajwerner commented 4 years ago

Is your feature request related to a problem? Please describe.

In PostgreSQL you can add a RETURNING (xmax = 0) AS inserted clause to determine which occurred. We really don't have an equivalent story.

Describe the solution you'd like I'm not sure. Given xmax and its semantics are never going to feature in cockroach, we'd need something else here. One thought is to lean on or extend the work in https://github.com/cockroachdb/cockroach/issues/50102 to provide access to the MVCC timestamp of the row when it was read in an UPDATE/UPSERT? To be honest, the value we're going to hand back during a transaction for that is weird, it's the provisional commit timestamp, but you know that it's above any previously read value and less than or equal to the commit timestamp.

Jira issue: CRDB-4123

RaduBerinde commented 3 years ago

A proposal here is to provide the option of returning a special bool column: RETURNING crdb_is_update (or crdb_inserted?)

github-actions[bot] commented 1 year ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!