Answer the question
In order to leave comments, you need to log in
SQLite: Why does ON CONFLICT IGNORE return a duplicate error?
Guided by the documentation, I created a table with a unique index and fields containing ignoring errors with duplicate records.
Here's the fiddle: sqlfiddle.com/#!7/77dc6/5
Logically, two out of three inserts should create records in the table, ignoring the duplicate error.
However, this does not happen.
The first three pages in Google on this topic (all links are purple :) ) claim that I'm doing everything right. But doesn't work. Why?
[SOLUTION]
The ON CONFLICT IGNORE condition (possible options in the documentation ) can be used in several cases.
1) when one column should be unique;
CREATE TABLE User (
id integer PRIMARY KEY,
first_name text NOT NULL UNIQUE ON CONFLICT IGNORE,
last_name text NOT NULL
);
CREATE TABLE User (
id integer PRIMARY KEY,
first_name text NOT NULL,
last_name text NOT NULL,
UNIQUE(first_name, last_name)
ON CONFLICT IGNORE
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question