Created
March 9, 2020 16:52
-
-
Save mcunha98/5a5a03364e9c796663ed3fcf667dc64d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DO $$ | |
| DECLARE r RECORD; | |
| BEGIN | |
| FOR r IN SELECT * FROM t LOOP | |
| BEGIN | |
| UPDATE t SET id = 2 WHERE des = 'foo' AND id = r.id; | |
| UPDATE t SET des = 'bar2' WHERE id = 2 AND id = r.id; | |
| EXCEPTION WHEN unique_violation THEN | |
| RAISE NOTICE 'Oups .. there was a conflict on % - %',r.id,r.des; | |
| END; | |
| END LOOP; | |
| END$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment