Reputation: 67
Is it possible to import a pipe(|) separated .txt file into a sqlite database without creating duplicate rows. Essentially I would like to always use the same file to import data into the sqlite database however, I only want it to import the new/unique elements within that file to the database.
I am using sqlite3 from the command line.
Upvotes: 0
Views: 183
Reputation: 180280
To disallow duplicates, use a UNIQUE or PRIMARY KEY constraint on the column(s) that identify the rows. To prevent errors when the duplicates are tried to be inserted, put an ON CONFLICT clause on the constraint:
CREATE TABLE MyTable (
X TEXT,
Y TEXT,
Z TEXT,
PRIMARY KEY (X, y) ON CONFLICT IGNORE
);
Upvotes: 1