SQLite Forum

Some comments about RETURNING
Login
I think that RETURNING should not need to be implemented in CTEs and subqueries.

However, I do think that diverting the returning into another table should be implemented. I don't know what PostgreSQL does, although if PostgreSQL doesn't already have a syntax for that (or its syntax is no good), then I can suggest:
```
RETURNING data_list [INTO [schema_name.]table_or_view[(column_list)] [returning_clause]]
```

You could also return into a view with one or more INSTEAD OF INSERT triggers, or a virtual table, in addition to ordinary tables.

If you use RETURNING INTO then you could chain them by adding more RETURNING clauses, including to return them in the result set too if you want to do. (Although, maybe chaining is not a high priority; perhaps we don't really need that.)

Also, as it turns out, for a program I was writing, supporting RETURNING for DELETE on virtual tables (at least for those that have a rowid) would be a useful thing to have.