diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
new file mode 100644
index 6db42e7..faba8b2
*** a/src/backend/executor/execUtils.c
--- b/src/backend/executor/execUtils.c
*************** ExecAssignResultTypeFromTL(PlanState *pl
*** 474,480 ****
  TupleDesc
  ExecGetResultType(PlanState *planstate)
  {
! 	TupleTableSlot *slot = planstate->ps_ResultTupleSlot;
  
  	return slot->tts_tupleDescriptor;
  }
--- 474,483 ----
  TupleDesc
  ExecGetResultType(PlanState *planstate)
  {
! 	TupleTableSlot *slot;
! 
! 	Assert(planstate != NULL);
! 	slot = planstate->ps_ResultTupleSlot;
  
  	return slot->tts_tupleDescriptor;
  }
diff --git a/src/backend/executor/nodeCtescan.c b/src/backend/executor/nodeCtescan.c
new file mode 100644
index 7ab15ac..e485c1a
*** a/src/backend/executor/nodeCtescan.c
--- b/src/backend/executor/nodeCtescan.c
*************** ExecInitCteScan(CteScan *node, EState *e
*** 255,262 ****
  	/*
  	 * The scan tuple type (ie, the rowtype we expect to find in the work
  	 * table) is the same as the result rowtype of the CTE query.
  	 */
! 	ExecAssignScanType(&scanstate->ss,
  					   ExecGetResultType(scanstate->cteplanstate));
  
  	/*
--- 255,265 ----
  	/*
  	 * The scan tuple type (ie, the rowtype we expect to find in the work
  	 * table) is the same as the result rowtype of the CTE query.
+ 	 * We must check for NULL because we don't initialize data-modifying
+ 	 * CTE's with a ModifyTable node at the top.
  	 */
! 	if (scanstate->cteplanstate != NULL)
! 		ExecAssignScanType(&scanstate->ss,
  					   ExecGetResultType(scanstate->cteplanstate));
  
  	/*
