Document that plpgsql upsert example can fail if insert triggers return

unique exception, or if not used in read committed transaction mode.
This commit is contained in:
Bruce Momjian 2011-02-17 13:36:36 -05:00
parent 732808c087
commit f87712d208
1 changed files with 5 additions and 2 deletions

View File

@ -2464,7 +2464,7 @@ BEGIN
INSERT INTO db(a,b) VALUES (key, data); INSERT INTO db(a,b) VALUES (key, data);
RETURN; RETURN;
EXCEPTION WHEN unique_violation THEN EXCEPTION WHEN unique_violation THEN
-- do nothing, and loop to try the UPDATE again -- Do nothing, and loop to try the UPDATE again.
END; END;
END LOOP; END LOOP;
END; END;
@ -2474,7 +2474,10 @@ LANGUAGE plpgsql;
SELECT merge_db(1, 'david'); SELECT merge_db(1, 'david');
SELECT merge_db(1, 'dennis'); SELECT merge_db(1, 'dennis');
</programlisting> </programlisting>
This example assumes the <literal>unique_violation</> error is caused by
the <command>INSERT</>, and not by an <command>INSERT</> trigger function
on the table. Also, this example only works in the default Read
Committed transaction mode.
</para> </para>
</example> </example>
</sect2> </sect2>