Improvements to the way vector assignment size checking is done.  Size checks
when the RHS is a SELECT are deferred until after "*" wildcards are expanded.

FossilOrigin-Name: 696219b11049930cdbc38f574820f4bbaf8621bb
diff --git a/manifest b/manifest
index 8e4c629..4c09a2f 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sthe\srow-values\sin\sUPDATE\sstatements\swithin\sTRIGGER\sproblem\sidentified\nby\sticket\s[8c9458e7].
-D 2017-01-03T01:24:10.074
+C Improvements\sto\sthe\sway\svector\sassignment\ssize\schecking\sis\sdone.\s\sSize\schecks\nwhen\sthe\sRHS\sis\sa\sSELECT\sare\sdeferred\suntil\safter\s"*"\swildcards\sare\sexpanded.
+D 2017-01-03T02:58:01.890
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -341,7 +341,7 @@
 F src/date.c dc3f1391d9297f8c748132813aaffcb117090d6e
 F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d
 F src/delete.c c8bc10d145c9666a34ae906250326fdaa8d58fa5
-F src/expr.c e115097aa866a462051ac8430757638dc1d73f1c
+F src/expr.c 1df03961abc008b46154edca14bcbb38e7a3be90
 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
 F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae
 F src/func.c d8582ee91975975645f206db332c38f534b783ad
@@ -1541,7 +1541,10 @@
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 16415b5aad445c9e4e849018b48538d74eec8944 14da99d41f7968bf816203b4ae11c1f0d1ee0b5d
-R b890811ca8348b8ceda7efec0ae53743
+P f12ed3ce0bfb2d94c9baad23fdcbd816c72439a1
+R c698fe9c623530e3a7438be4c43f0c89
+T *branch * vector-size-check
+T *sym-vector-size-check *
+T -sym-trunk *
 U drh
-Z 378863182d1610dbd664d17105221a9b
+Z 0057cd8fc280f2ed6a1015934452d1e9
diff --git a/manifest.uuid b/manifest.uuid
index 2c93085..9a1e5a3 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-f12ed3ce0bfb2d94c9baad23fdcbd816c72439a1
\ No newline at end of file
+696219b11049930cdbc38f574820f4bbaf8621bb
\ No newline at end of file
diff --git a/src/expr.c b/src/expr.c
index 6d4b48f..6e615fe 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -414,9 +414,10 @@
     assert( pVector->flags & EP_xIsSelect );
     /* The TK_SELECT_COLUMN Expr node:
     **
-    ** pLeft:           pVector containing TK_SELECT
+    ** pLeft:           pVector containing TK_SELECT.  Not deleted.
     ** pRight:          not used.  But recursively deleted.
     ** iColumn:         Index of a column in pVector
+    ** iTable:          0 or the number of columns on the LHS of an assignment
     ** pLeft->iTable:   First in an array of register holding result, or 0
     **                  if the result is not yet computed.
     **
@@ -1519,13 +1520,19 @@
   ** exit prior to this routine being invoked */
   if( NEVER(pColumns==0) ) goto vector_append_error;
   if( pExpr==0 ) goto vector_append_error;
-  n = sqlite3ExprVectorSize(pExpr);
-  if( pColumns->nId!=n ){
+
+  /* If the RHS is a vector, then we can immediately check to see that 
+  ** the size of the RHS and LHS match.  But if the RHS is a SELECT, 
+  ** wildcards ("*") in the result set of the SELECT must be expanded before
+  ** we can do the size check, so defer the size check until code generation.
+  */
+  if( pExpr->op!=TK_SELECT && pColumns->nId!=(n=sqlite3ExprVectorSize(pExpr)) ){
     sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
                     pColumns->nId, n);
     goto vector_append_error;
   }
-  for(i=0; i<n; i++){
+
+  for(i=0; i<pColumns->nId; i++){
     Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i);
     pList = sqlite3ExprListAppend(pParse, pList, pSubExpr);
     if( pList ){
@@ -1534,11 +1541,20 @@
       pColumns->a[i].zName = 0;
     }
   }
+
   if( pExpr->op==TK_SELECT ){
     if( pList && pList->a[iFirst].pExpr ){
-      assert( pList->a[iFirst].pExpr->op==TK_SELECT_COLUMN );
-      pList->a[iFirst].pExpr->pRight = pExpr;
+      Expr *pFirst = pList->a[iFirst].pExpr;
+      assert( pFirst->op==TK_SELECT_COLUMN );
+     
+      /* Store the SELECT statement in pRight so it will be deleted when
+      ** sqlite3ExprListDelete() is called */
+      pFirst->pRight = pExpr;
       pExpr = 0;
+
+      /* Remember the size of the LHS in iTable so that we can check that
+      ** the RHS and LHS sizes match during code generation. */
+      pFirst->iTable = pColumns->nId;
     }
   }
 
@@ -3732,9 +3748,17 @@
       break;
     }
     case TK_SELECT_COLUMN: {
+      int n;
       if( pExpr->pLeft->iTable==0 ){
         pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft, 0, 0);
       }
+      assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT );
+      if( pExpr->iTable
+       && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft)) 
+      ){
+        sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
+                                pExpr->iTable, n);
+      }
       return pExpr->pLeft->iTable + pExpr->iColumn;
     }
     case TK_IN: {