I'm trying to insert duplicates data to table B
when PKA
violated using a BEFORE INSERT TRIGGER
as the following example:
CREATE TABLE A( Col INTEGER, Coll TEXT(25), CONSTRAINT PKA PRIMARY KEY(Col, Coll) ON CONFLICT IGNORE);
CREATE UNIQUE INDEX IX_A ON A(Col, Coll);
CREATE TABLE B( Col INTEGER, Coll TEXT(25));
CREATE INDEX IX_B ON B(Col, Coll);
CREATE TRIGGER Trig
BEFORE INSERT
ON A
WHEN (Col = New.Col AND Coll = New.Coll)
BEGIN
INSERT INTO B(Col, Coll) VALUES(New.Col, New.Coll);
END;
But, it seems like the column Col
is not accessible there, so it throws:
no such column: Col
Even when I change the conditions to
New.Col IN(SELECT Col FROM A)
AND
New.Coll IN(SELECT Coll FROM A)
I get another error message:
UNIQUE constraint failed: A.Col, A.Coll
While it shouldn't because of ON CONFLICT IGNORE
.
- Why did I get those error messages? (What's the cause).
- How can I use the trigger to insert duplicates into another table?