diff -rpcd a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
*** a/src/interfaces/libpq/fe-exec.c	2013-12-02 09:17:05.000000000 +0900
--- b/src/interfaces/libpq/fe-exec.c	2013-12-20 14:28:50.000000000 +0900
*************** PQputCopyEnd(PGconn *conn, const char *e
*** 2265,2278 ****
  			if (pqPutMsgStart('f', false, conn) < 0 ||
  				pqPuts(errormsg, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				return -1;
  		}
  		else
  		{
  			/* Send COPY DONE */
  			if (pqPutMsgStart('c', false, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				return -1;
  		}
  
  		/*
--- 2265,2278 ----
  			if (pqPutMsgStart('f', false, conn) < 0 ||
  				pqPuts(errormsg, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				goto fail;
  		}
  		else
  		{
  			/* Send COPY DONE */
  			if (pqPutMsgStart('c', false, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				goto fail;
  		}
  
  		/*
*************** PQputCopyEnd(PGconn *conn, const char *e
*** 2283,2289 ****
  		{
  			if (pqPutMsgStart('S', false, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				return -1;
  		}
  	}
  	else
--- 2283,2289 ----
  		{
  			if (pqPutMsgStart('S', false, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				goto fail;
  		}
  	}
  	else
*************** PQputCopyEnd(PGconn *conn, const char *e
*** 2293,2299 ****
  			/* Ooops, no way to do this in 2.0 */
  			printfPQExpBuffer(&conn->errorMessage,
  							  libpq_gettext("function requires at least protocol version 3.0\n"));
! 			return -1;
  		}
  		else
  		{
--- 2293,2299 ----
  			/* Ooops, no way to do this in 2.0 */
  			printfPQExpBuffer(&conn->errorMessage,
  							  libpq_gettext("function requires at least protocol version 3.0\n"));
! 			goto fail;
  		}
  		else
  		{
*************** PQputCopyEnd(PGconn *conn, const char *e
*** 2301,2307 ****
  			if (pqPutMsgStart(0, false, conn) < 0 ||
  				pqPutnchar("\\.\n", 3, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				return -1;
  		}
  	}
  
--- 2301,2307 ----
  			if (pqPutMsgStart(0, false, conn) < 0 ||
  				pqPutnchar("\\.\n", 3, conn) < 0 ||
  				pqPutMsgEnd(conn) < 0)
! 				goto fail;
  		}
  	}
  
*************** PQputCopyEnd(PGconn *conn, const char *e
*** 2317,2322 ****
--- 2317,2332 ----
  		return -1;
  
  	return 1;
+ 
+ fail:
+ 
+ 	/*
+ 	 * Switch back to BUSY so that PQgetResult will process any unread data
+ 	 * (typically, a NOTICE message from the backend telling us it's
+ 	 * committing hara-kiri, and report failure.
+ 	 */
+ 	conn->asyncStatus = PGASYNC_BUSY;
+ 	return -1;
  }
  
  /*
