Avoid spurious "no such table" errors in statements of the form "INSERT INTO tbl WITH xxx AS (...) SELECT * FROM xxx".
FossilOrigin-Name: cccff8a0b427feb05cc8952a765b829e731394fd
diff --git a/src/insert.c b/src/insert.c
index b4bd6b7..a236636 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -667,8 +667,7 @@
**
** This is the 2nd template.
*/
- if( pColumn==0 && pParse->pWith==0
- && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
+ if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){
assert( !pTrigger );
assert( pList==0 );
goto insert_end;
@@ -1859,6 +1858,12 @@
if( pSelect==0 ){
return 0; /* Must be of the form INSERT INTO ... SELECT ... */
}
+ if( pParse->pWith || pSelect->pWith ){
+ /* Do not attempt to process this query if there are an WITH clauses
+ ** attached to it. Proceeding may generate a false "no such table: xxx"
+ ** error if pSelect reads from a CTE named "xxx". */
+ return 0;
+ }
if( sqlite3TriggerList(pParse, pDest) ){
return 0; /* tab1 must not have triggers */
}