Skip to content

Instantly share code, notes, and snippets.

@mcunha98
Created March 9, 2020 16:52
Show Gist options
  • Select an option

  • Save mcunha98/5a5a03364e9c796663ed3fcf667dc64d to your computer and use it in GitHub Desktop.

Select an option

Save mcunha98/5a5a03364e9c796663ed3fcf667dc64d to your computer and use it in GitHub Desktop.
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