Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN
- LOOP
- -- first check if this number is already present in list with id 1
- SELECT * from test_co.list_numbers where lists_id='1' and numbers_id= '2';
- IF found THEN
- RETURN;
- END IF;
- -- not there, so try to insert the phone_id and the list_id
- -- if someone else inserts the same key concurrently,
- -- we could get a unique-key failure
- BEGIN
- --if it's not present, then insert it
- INSERT INTO test_co.list_numbers (lists_id, numbers_id) VALUES (1, 2);
- RETURN;
- EXCEPTION WHEN unique_violation THEN
- -- do nothing, and loop to try the UPDATE again
- END;
- END LOOP;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement