Postgres bulk insert control errors

32 Views Asked by At

Is there any way to control errors in a bulk execution with a PostgreSQL script? I'm trying to migrate data from one table to another, and what I need is that, in case of failure of any record, instead of stopping the script execution, the failed data is saved in a new error table. I've seen a workaround that works with keys-found https://dba.stackexchange.com/questions/311280/is-it-possible-to-call-a-function-using-the-on-conflict-event but it doesn't work for me.

My script is as follows:

INSERT INTO schema.table(id, code)
SELECT uuid_generate_v4(), t.code
FROM sch.tab t
ON CONFLICT DO NOTHING;

Instead of DO NOTHING, could a function be called to insert the failed record (id and code) into another table?

0

There are 0 best solutions below