SQLite Forum

CTEs in triggers
Login
[The documentation](https://www.sqlite.org/lang_createtrigger.html) states that:

> Common table expression are not supported for statements inside of triggers.

However, I seem to be able to use CTEs in triggers in  `INSERT INTO` statements so long as the CTE is nested. For example, the following silly code seems to work:

```sql
CREATE TABLE src(content);
CREATE TABLE dst(content);
CREATE TRIGGER copy_content INSERT ON src BEGIN
  INSERT INTO dst SELECT (
    WITH loophole AS (SELECT new.content)
    SELECT * FROM loophole
  );
END;
INSERT INTO src VALUES(1);
```

I would appreciate some clarification. Why are CTEs restricted in some cases? Will nesting CTEs in `SELECT()` in triggers cause terrible things to happen?