Force transaction to be aborted in a `RETURNING NOTHING` statement

I’m doing a simplistic “locking” mechanism where owner of the lock would have a “token” that must match that in the database.

Most of the time, token would match and everything would work fine. However, if token does not match, I want to abort the whole transaction with some error code.

One way to do that would be to simply return flag from the statement itself and if it is not 1 (or whatever is used to indicate success), fail the transaction.

However, I would like for that statement to be RETURNING NOTHING, so I don’t wait for it to complete. I could be over-optimizing here, but given that most of the time it should succeed, I would rather have it abort transaction server-side.

So far I tried doing silly things like inserting NULL in NON-NULL column if token does not match, but that cause CockroachDB to corrupt the table & crush ( :upside_down_face:

Is where a nice way to do that?

You can cause a division by zero, this will create an error. For example IF(yourcondition, 1/0, 123).

Would this help?