Subject | Deleting a duplicate row from a corrupt database |
---|---|
Author | Ales Smodis |
Post date | 2004-05-13T10:33:36Z |
Hello!
I've got a database file (SQL dialect 3, ODS version 10.0) from an
Interbase server (version WI-V6.0.1.0) that has a corrupt index on the
primary key of a table. I've upgraded the server to Firebird 1.5 and
would like to pump the data from the old database to an empty new one
(the new one has a few more objects; I'll essentially be upgrading the
database, too). To do that I obviously need the old database without
duplicate rows.
I've made a backup of the corrupt database and tried to restore from it,
but to no avail: gbak complains about an index. I've run database
validation from within IBConsole and tried backup and restore again, but
the same error occured. I've identified the key of the duplicate rows
and displayed them with a simple trick:
select rep_id, doc_id, doc_year, doc_no, count(*)
from document_head
group by rep_id, doc_id, doc_year, doc_no
plan (document_head natural)
order by 5 desc;
select * from document_head
where <key names with values>
plan (document_head natural);
Those four fields form the key of the table.
So I'm left with two rows with the same key and don't know how to delete
one of them since the delete statement doesn't take a plan and whatever
condition I use to identify the row I want to delete, it always uses an
index.
I can of course filter out such disrepancies at data pumping, but would
like to know if there is a way of deleting a row in such a situation,
without deleting both rows and then inserting the right one. I'm not
even sure if what I'm asking is reasonable. :)
-Ales
I've got a database file (SQL dialect 3, ODS version 10.0) from an
Interbase server (version WI-V6.0.1.0) that has a corrupt index on the
primary key of a table. I've upgraded the server to Firebird 1.5 and
would like to pump the data from the old database to an empty new one
(the new one has a few more objects; I'll essentially be upgrading the
database, too). To do that I obviously need the old database without
duplicate rows.
I've made a backup of the corrupt database and tried to restore from it,
but to no avail: gbak complains about an index. I've run database
validation from within IBConsole and tried backup and restore again, but
the same error occured. I've identified the key of the duplicate rows
and displayed them with a simple trick:
select rep_id, doc_id, doc_year, doc_no, count(*)
from document_head
group by rep_id, doc_id, doc_year, doc_no
plan (document_head natural)
order by 5 desc;
select * from document_head
where <key names with values>
plan (document_head natural);
Those four fields form the key of the table.
So I'm left with two rows with the same key and don't know how to delete
one of them since the delete statement doesn't take a plan and whatever
condition I use to identify the row I want to delete, it always uses an
index.
I can of course filter out such disrepancies at data pumping, but would
like to know if there is a way of deleting a row in such a situation,
without deleting both rows and then inserting the right one. I'm not
even sure if what I'm asking is reasonable. :)
-Ales