I'm trying to create a BEFORE INSERT
trigger in Sqlite that catches my unique primary key column (UID) during import and replaces the remaining columns. I'm using sqlite3 command line for CSV import and whenever it sees an existing UID it doesn't update the other columns. This is the trigger I've played around with.
tldr: I want the other columns on a row to be replaced or updated during import with (UID) PRIMARY
CREATE TABLE "AllInventory"
(
"UID" TEXT,
"LotNumber" INTEGER,
"ItemType" TEXT,
"AuctionDate" TEXT,
"AuctionHouse" TEXT,
"Location" TEXT,
PRIMARY KEY("UID")
)
CREATE TRIGGER BULK_Inventory_Update
BEFORE INSERT ON AllInventory
FOR EACH ROW
WHEN EXISTS (SELECT * FROM AllInventory WHERE UID = New.UID)
BEGIN
INSERT OR REPLACE INTO AllInventory(UID, LotNumber, ItemType, AuctionDate, AuctionHouse, Location)
VALUES (new.UID, new.LotNumber, new.ItemType, new.AuctionDate, new.AuctionHouse, new.Location)
ON CONFLICT (UID) DO UPDATE SET LotNumber = new.LotNumber, ItemType = new.ItemType, AuctionDate = new.AuctionDate,
AuctionHouse = new.AuctionHouse, Location = new.Location;
END