1
I have a script in python that searches elements of a database and saves in another, so when I run the script it is duplicating the data.
sql = "INSERT INTO `alarm` (`data`, `seconds`, `culprit`, `status`) VALUES (%s, %s, %s, %s)
Is there any way I can change this INSERT to insert only what is not contained.
If you want to be complete, you also have the
INSERT INTO... SELECT
– Jefferson Quesado
+1 for the ways to do SQL, but do not forget that between two different databases, the primary key that is usually a numeric ID will hardly be the same. (In case of using a UUID it is even possible to use the same key for the same object between different databases). Anyway, yes, you have to define which duplicate values make the record be considered "duplicated", with the use of a single key.
– jsbueno
That.. of "usually being a numeric id" is a vague statement. If modeling is done well, the primary key really needs to identify the record. In the case of an alarm, it could be a timestamp combined with a user code, for example.
– Carlos Cariello