How to avoid duplicate records when using datainsert?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Neil Caithness
le 21 Jan 2016
Commenté : Neil Caithness
le 22 Jan 2016
datainsert fails when it encounters any duplicate records. Is there a way to specify it should just skip the duplicates, perhaps returning an index of the successful inserts?
datainsert(conn,'consdata',colnames,tbl)
Error using database.ODBCConnection/insert (line 264)
ODBC Driver Error: ERROR: duplicate key value violates unique constraint "consdata_pkey";
Error while executing the query
0 commentaires
Réponse acceptée
Roger Wohlwend
le 22 Jan 2016
No, you can't specify something like that. If you want datainsert to continue with the next dataset if it encounters a duplicate, just use try-catch.
try
datainsert(conn,'consdata',colnames,tbl)
catch E
% This section is only executed if a duplicate record exists. So if you want
% Matlab to remember when datainsert failed because of a duplicate record,
% put some code here. For expample if you execute this try-catch within a
% Loop, write the Loop index to a vector.
end
3 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Database Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!