*** a/contrib/postgres_fdw/deparse.c
--- b/contrib/postgres_fdw/deparse.c
***************
*** 252,257 **** foreign_expr_walker(Node *node,
--- 252,265 ----
  				if (var->varno == glob_cxt->foreignrel->relid &&
  					var->varlevelsup == 0)
  				{
+ 					/*
+ 					 * System columns can't be sent to remote.
+ 					 *
+ 					 * XXX: we should probably send ctid to remote.
+ 					 */
+ 					if (var->varattno < 0)
+ 						return false;
+ 
  					/* Var belongs to foreign table */
  					collation = var->varcollid;
  					state = OidIsValid(collation) ? FDW_COLLATE_SAFE : FDW_COLLATE_NONE;
***************
*** 1261,1266 **** deparseVar(Var *node, deparse_expr_cxt *context)
--- 1269,1279 ----
  	if (node->varno == context->foreignrel->relid &&
  		node->varlevelsup == 0)
  	{
+ 		/*
+ 		 * System columns shouldn't be examined here.
+ 		 */
+ 		Assert(node->varattno >= 0);
+ 
  		/* Var belongs to foreign table */
  		deparseColumnRef(buf, node->varno, node->varattno, context->root);
  	}
