In PostgreSQL I am inserting several rows to a table from select. If there is some constraint violation I can see an error that shows data that violates constraint. But only one row.
Is there a way to see all rows that violates constraints? I know one solution use PLSQL and cursor, but this is toooo slow for my case. Any other solution? Sample code that illustrates the issue.
create table t_source (id int, ref int);
insert into t_source (id,ref) values (1,1),(1,2),(1,3),(1,4),(1,5);
create table t_dict(id int primary KEY, name varchar);
insert into t_dict (id,name) values (2,'two'),(3,'three');
create table t_target (
id int, ref int,
FOREIGN KEY (ref) REFERENCES t_dict(id)
);
insert into t_target (id,ref) select id,ref from t_source;
shows one error:
SQL Error [23503]: ERROR: insert or update on table "t_target" violates foreign key constraint "t_target_ref_fkey"
Detail: Key (ref)=(1) is not present in table "t_dict".