Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -2526,11 +2526,11 @@ case SRT_Coroutine: { if( pDest->iSdst==0 ){ pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst); pDest->nSdst = pIn->nSdst; } - sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pDest->nSdst); + sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst); sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm); break; } /* If none of the above, then the result destination must be Index: test/insert2.test ================================================================== --- test/insert2.test +++ test/insert2.test @@ -14,10 +14,11 @@ # # $Id: insert2.test,v 1.19 2008/01/16 18:20:42 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix insert2 # Create some tables with data that we can select against # do_test insert2-1.0 { execsql {CREATE TABLE d1(n int, log int);} @@ -272,7 +273,26 @@ INSERT INTO t2 SELECT (SELECT a FROM t2), 4; SELECT * FROM t2; } } {1 2 1 3 1 4} } + +do_execsql_test 6.0 { + CREATE TABLE t5(a, b, c DEFAULT 'c', d); +} +do_execsql_test 6.1 { + INSERT INTO t5(a) SELECT 456 UNION ALL SELECT 123 ORDER BY 1; + SELECT * FROM t5 ORDER BY rowid; +} {123 {} c {} 456 {} c {}} + +ifcapable fts3 { + do_execsql_test 6.2 { + CREATE VIRTUAL TABLE t0 USING fts4(a); + } + do_execsql_test 6.3 { + INSERT INTO t0 SELECT 0 UNION SELECT 0 AS 'x' ORDER BY x; + SELECT * FROM t0; + } {0} +} + finish_test