I tried to test that problem on this sqlite3 version with -DSQLITE_DEBUG and assertion fails there.Since flattening only makes another compound select-stmt with ORDER BY clause I guess error wasoccuring on flattened version of it. Moreover in latter versions of sqlite3 this assert was deleted and therestriction check wasn't fixed. So I assume sqlite3 developers just don't know about it or don't aim onfixing it as the error anyways occurs but on flattened subquery.Here is original fix of this assertion fail (JFYI):