postgresql - Restoring only some key values using COPY STDIN in Postgres? -
i accidentally ran query on live info deleted 5000 odd rows. made backup before did this, , backup in format:
copy table (id, "position", event) stdin; 529 1 5283 648 1 6473 687 1 6853 \.
problem is, if run it, get:
error: duplicate key value violates unique constraint "table_pkey"
is there way alter query insert rows deleted? "if exists, ignore" kind of thing? know affects many things, because it's literally entries need replaced, think work, don't know if exists?
easiest way may create re-create of original table , restore that. insert original table re-create no entry exists in original. e.g.
create table copy_table select * table 1=2; -- alter re-create statement re-create copy_table stdin; ... -- insert original insert table t1 select ct.* copy_table ct left bring together table t2 on t2.id = ct.id -- assuming id primary key t2.id null;
postgresql
No comments:
Post a Comment