Question

I currently have this trigger in MySQL. (On Table 1, EVENT: Before Insert)

set new.combinedColumn = concat(trim(new.column1), trim(new.column2))

How do I combine two columns like this, except in SQLite? I've tried multiple different ways and haven't been able to get a working statement.

This is what i have so far

BEFORE INSERT ON [Table] 
FOR EACH ROW 
BEGIN 

set Column1 = column2 || column3;

END >

i get the error

5/9/2014 2:19:34 PM: SQL Error: near "set": syntax error  <CREATE TRIGGER [insert] 
Was it helpful?

Solution

SQLite has no SET statement; the only statements allowed in triggers are SELECT/INSERT/UPDATE/DELETE. Therefore, you cannot affect the values to be inserted in the trigger; you have to update the table afterwards:

CREATE TRIGGER [...]
AFTER INSERT ON MyTable
FOR EACH ROW
BEGIN
    UPDATE MyTable
    SET Column1 = Column2 || Column3   -- or trim(...)
    WHERE rowid = NEW.rowid;
END;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top