SQLite Forum

Avoiding adding duplicate entries
Login
"OR REPLACE" and "OR IGNORE" are what are known as "conflict resolution method".  In order for them to have any effect whatsoever, you must *firstly* have a conflict.

However, you have not specified "a conflict", so without a "conflict" to resolve, the "conflict resolution method" is never invoked.

So if you want the column `table1.timestamp` to be unique you can either declare that column to be `unique` in the table declaration **OR** create a unique index on that column.  The former is merely syntactic sugar for the latter.  (Syntactic sugar means that it does the same thing but is a different (sweeter, probably as in simpler) way of expressing the same result.  ((Note that this may not be the case in all RDBMS implementations, however, it is the case for SQLite3))

So, if you create a unique index:

```
create unique index table1timestamp on table1(timestamp);
```

then a **conflict** will arise if you attempt to INSERT a record with a duplicate timestamp into the table1 table.  This will require the use of the "conflict resolution method" to handle if you do not want to "see" an error being "bubbled up" to the application.  

The "REPLACE" conflict resolution method means that conflicting records (in this case those with the same timestamp value) will be deleted and then the new record inserted.  

The "IGNORE" conflict resolution method means that the fact of the conflict is ignored and the insert is ignored.

So the long and short of it is that before a "conflict resolution method" will be invoked, there must be a conflict which the specified "resolution method" will be capable of resolutioning.