I am looking to understand how to properly handle errors and move them. I would like to take an error and dump that error into another table which I plan to scan later. How would i go about doing that in the example below?
-----my main table
CREATE TABLE stage(test_date VARCHAR);
-----error table
CREATE TABLE errors (
error VARCHAR,
the_date timestamp
);
-----function that will handle insert and log error into errors table
CREATE OR REPLACE PROCEDURE example4 () AS $$
BEGIN
INSERT INTO prd (test_date) VALUES ('hello');
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Insert failed with error code %', SQLSTATE;
---INSERT INTO errors table???
---Im imagining something like INSERT INTO errors (error, the_date) ...
END;
$$
LANGUAGE plpgsql;