BEGIN
INSERT INTO main (name, created) VALUES (i_name, CURRENT_TIMESTAMP
AT TIME ZONE 'GMT');
EXCEPTION WHEN UNIQUE_VIOLATION THEN
-- RETURN 'error: already exists';
exec 'INSERT INTO error_main (name, error) select (name,
''UNIQUE_VIOLATION'') from main';
END;
如果可以存储已知错误的记录并且已完成特定的异常处理。并将此列信息存储在另一个表中。
答案 0 :(得分:0)
您不需要动态SQL,请尝试简单的INSERT
:
BEGIN
INSERT INTO main (name, created)
VALUES (i_name, CURRENT_TIMESTAMP AT TIME ZONE 'GMT');
EXCEPTION WHEN UNIQUE_VIOLATION THEN
INSERT INTO error_main (name, error)
SELECT i_name, 'UNIQUE_VIOLATION';
END;