Re: [GENERAL] How to handle simultaneous FOR-IN UPDATE-RETURNING loops? - Mailing list pgsql-general

From Alexander Farber
Subject Re: [GENERAL] How to handle simultaneous FOR-IN UPDATE-RETURNING loops?
Date
Msg-id CAADeyWi5JJN8TgNajx5KfP0ajynSbsKTmfva4SvSLp621Kf1VQ@mail.gmail.com
Whole thread Raw
In response to [GENERAL] How to handle simultaneous FOR-IN UPDATE-RETURNING loops?  (Alexander Farber <alexander.farber@gmail.com>)
Responses Re: [GENERAL] How to handle simultaneous FOR-IN UPDATE-RETURNING loops?
List pgsql-general
I have tried:

  FOR _gid, _loser, _winner IN
        UPDATE  words_games
        SET     finished = CURRENT_TIMESTAMP
        WHERE   finished IS NULL
        AND     played1 IS NOT NULL
        AND     played2 IS NOT NULL
        AND     (played1 < CURRENT_TIMESTAMP - INTERVAL '24 hours'
        OR       played2 < CURRENT_TIMESTAMP - INTERVAL '24 hours')
        RETURNING
                gid,
                CASE WHEN played1 < played2 THEN player1 ELSE player2 END,
                CASE WHEN played1 < played2 THEN player2 ELSE player1 END
        FOR UPDATE SKIP LOCKED
  LOOP
    ...
  END LOOP;

but this fails with:

    ERROR:  syntax error at or near "FOR"

I have also described my problem at SO:

    https://stackoverflow.com/questions/45015368/how-to-handle-simultaneous-for-in-update-returning-loops

Thank you
Alex

pgsql-general by date:

Previous
From: Thomas Munro
Date:
Subject: Re: [GENERAL] Concurrency and UPDATE [...] FROM
Next
From: rihad
Date:
Subject: Re: [GENERAL] Changing collate & ctype for an existing database