code: func retryTxCockroach(tx *sql.Tx, stmts func() error) error {
  	// Specify that we intend to retry this txn in case of CockroachDB retryable
  	// errors.
  	if _, err := tx.Exec("SAVEPOINT cockroach_restart"); err != nil {
  		return err
  	}
  
  	for {
  		released := false
  
  		err := stmts()
  
  		if err == nil {
  			// RELEASE acts like COMMIT in CockroachDB. We use it since it gives us an
  			// opportunity to react to retryable errors, whereas tx.Commit() doesn't.
  			released = true
  			if _, err = tx.Exec("RELEASE SAVEPOINT cockroach_restart"); err == nil {
  				return nil
  			}
  		}
  		// We got an error; let's see if it's a retryable one and, if so, restart. We look
  		// for either the standard PG errcode SerializationFailureError:40001 or the Cockroach extension
  		// errcode RetriableError:CR000. The Cockroach extension has been removed server-side, but support
  		// for it has been left here for now to maintain backwards compatibility.
  		pgErr, ok := err.(pgx.PgError)
  		if retryable := ok && (pgErr.Code == "CR000" || pgErr.Code == "40001"); !retryable {
  			if released {
  				err = &AmbiguousCommitError{err}
  			}
  			return err
  		}
  		if _, err = tx.Exec("ROLLBACK TO SAVEPOINT cockroach_restart"); err != nil {
  			return err
  		}
  	}
  }
docs: // retryTxCockroach runs the transaction and will retry in case of a retryable error.
  // https://www.cockroachlabs.com/docs/transactions.html#client-side-transaction-retries