擅长:python、mysql、java
<p>我将使用一个存储过程来捕获您的唯一冲突的异常。示例:</p>
<pre><code>CREATE OR REPLACE FUNCTION my_insert(i_foo text, i_bar text)
RETURNS boolean LANGUAGE plpgsql AS
$BODY$
begin
insert into foo(x, y) values(i_foo, i_bar);
exception
when unique_violation THEN -- nothing
return true;
end;
$BODY$;
SELECT my_insert('value 1','another value');
</code></pre>