필터 지우기
필터 지우기

sqlwrite - overwrite existing records

조회 수: 8 (최근 30일)
Ben Mercer
Ben Mercer 2018년 12월 13일
댓글: MEP 2022년 1월 25일
I'm using the sqlwrite method to write tables of data into an SQLite database. If there are existing records in the database with the same primary key value, sqlite throws an error. I'd like it to instead overwrite those existing records.
I've seen on other forums that in SQL, you can use the "REPLACE" command, which behaves like "INSERT", but overwrites records with a conflicting primary key, rather than throwing an error. However, it doesn't look like this option is accessible from outside of sqlwrite.
Another option would be to pre-emptively find and delete any records with a conflicting primary key. Is it possible for Matlab to programmatically determine which field is the primary key of a SQL table? I'd rather not have to hard code it separately if possible.
Many thanks,
Ben
  댓글 수: 2
gaoliming gao
gaoliming gao 2020년 6월 9일
It seems sqlwrite does not have the features.
Use try, catch statement, or use execute function with CONLICT ON command for postgresql.
MEP
MEP 2022년 1월 25일
I have the same problem, how can I solve it?

댓글을 달려면 로그인하십시오.

답변 (1개)

Dredging Production
Dredging Production 2019년 1월 29일
Are you using an ODBC connection? If yes you could try whether 'update' does the job:
However, I'm using a JDBC driver, and this function works for ODBC only - I guess.
If you know a solution for JDBC, I'd llike to hear it. Thank you!

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by