Note that there are some explanatory texts on larger screens.

plurals
  1. USMatt
    primarykey
    data
    text
    plurals
    1. COThe mismatched table names are a typo (now corrected). I knew you could set local variable with a SELECT, but I'd never tried it with an UPDATE, so that might just do the trick. Regarding the serializable transaction, my (admittedly imperfect) understanding is that if you don't use some sort of lock you can get unique key constraint violations and that "UPDATE with (serializable)" appropriately does this w/out deadlocks. I'm working from the example in the linked question (above) and still reading/trying to make sure I understand exactly what that does.
      singulars
    2. CO@AlexKuznetsov - Yes, RowLocked is supposed to be a table column; in reality, there are a couple columns that dictate whether or not a row should be "locked" (i.e. not updated by this procedure) but I simplified my SQL to try to make my question more clear; got a little sloppy with the syntax though - it should, of course, be "AND RowLocked = 0" and I should have mentioned it's a bit column.
      singulars
    3. COI always thought that you weren't supposed to rely on error handlers for "normal" processing, i.e. if I know that a typical use case will raise an exception, then I should check for that condition and handle it before it raises an exception. So I agree, it does feel a little dirty ;) If I can get the isolation level right (I'm still reading) then the logic is fairly straightforward - but I lose the original advantage of the upsert (i.e. no extra DB read).
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload