I don't think the question is related to C++ itself, I only added the tag because I'm using C++. Also, the code I posted works, but, as I explained, I don't know if it is guaranteed to work in all cases. It's SQLite's documentation what says you can't put WITHs inside TRIGGERs, but it does not specify any languages, so I suppose that it happens in all languages.