I believe we have a project policy that all user-facing error reports
should go through ereport not elog (so that they're translatable) and
should not have ERRCODE_INTERNAL_ERROR as SQLSTATE.  It's sometimes
debatable where the line is between user-facing and not, but surely any
error that is triggered by the standard regression tests has to be
considered user-facing.  Yet running the tests with log_error_verbosity
set to verbose turns up quite a few XX000 log entries.

The attached patch fixes all the cases exposed by the regression tests.
I also went through each affected file and adjusted any other elog or
ereport calls that seemed to need it, on the theory that such oversights
probably travel in herds.  I don't pretend that this is a complete fix,
but it's at least a down payment on the problem.

Probably the main thing that's worth discussing here is what to do in
plperl/plpython/pltcl when reporting an error thrown from the respective
language interpreter; in most cases we don't have a clear idea what
SQLSTATE should be used, but that doesn't make ERRCODE_INTERNAL_ERROR an
acceptable choice.  I used ERRCODE_EXTERNAL_ROUTINE_EXCEPTION where there
was not an obviously better candidate, but I wonder if anyone has a
different idea?

I propose to back-patch this into 9.5, but not further; it's not an
important enough issue to justify changing SQLSTATE behavior in stable
branches.

                        regards, tom lane

diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 8a95d47..cb1d029 100644
*** a/contrib/tablefunc/tablefunc.c
--- b/contrib/tablefunc/tablefunc.c
*************** crosstab(PG_FUNCTION_ARGS)
*** 432,438 ****
  			break;
  		default:
  			/* result type isn't composite */
! 			elog(ERROR, "return type must be a row type");
  			break;
  	}
  
--- 432,440 ----
  			break;
  		default:
  			/* result type isn't composite */
! 			ereport(ERROR,
! 					(errcode(ERRCODE_DATATYPE_MISMATCH),
! 					 errmsg("return type must be a row type")));
  			break;
  	}
  
*************** build_tuplestore_recursively(char *key_f
*** 1350,1356 ****
  				appendStringInfo(&chk_current_key, "%s%s%s",
  								 branch_delim, current_key, branch_delim);
  				if (strstr(chk_branchstr.data, chk_current_key.data))
! 					elog(ERROR, "infinite recursion detected");
  			}
  
  			/* OK, extend the branch */
--- 1352,1360 ----
  				appendStringInfo(&chk_current_key, "%s%s%s",
  								 branch_delim, current_key, branch_delim);
  				if (strstr(chk_branchstr.data, chk_current_key.data))
! 					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_RECURSION),
! 							 errmsg("infinite recursion detected")));
  			}
  
  			/* OK, extend the branch */
*************** validateConnectbyTupleDesc(TupleDesc tup
*** 1429,1435 ****
  	{
  		if (tupdesc->natts != (CONNECTBY_NCOLS + serial_column))
  			ereport(ERROR,
! 					(errcode(ERRCODE_SYNTAX_ERROR),
  					 errmsg("invalid return type"),
  					 errdetail("Query-specified return tuple has " \
  							   "wrong number of columns.")));
--- 1433,1439 ----
  	{
  		if (tupdesc->natts != (CONNECTBY_NCOLS + serial_column))
  			ereport(ERROR,
! 					(errcode(ERRCODE_DATATYPE_MISMATCH),
  					 errmsg("invalid return type"),
  					 errdetail("Query-specified return tuple has " \
  							   "wrong number of columns.")));
*************** validateConnectbyTupleDesc(TupleDesc tup
*** 1438,1444 ****
  	{
  		if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
  			ereport(ERROR,
! 					(errcode(ERRCODE_SYNTAX_ERROR),
  					 errmsg("invalid return type"),
  					 errdetail("Query-specified return tuple has " \
  							   "wrong number of columns.")));
--- 1442,1448 ----
  	{
  		if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
  			ereport(ERROR,
! 					(errcode(ERRCODE_DATATYPE_MISMATCH),
  					 errmsg("invalid return type"),
  					 errdetail("Query-specified return tuple has " \
  							   "wrong number of columns.")));
*************** validateConnectbyTupleDesc(TupleDesc tup
*** 1447,1460 ****
  	/* check that the types of the first two columns match */
  	if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("First two columns must be the same type.")));
  
  	/* check that the type of the third column is INT4 */
  	if (tupdesc->attrs[2]->atttypid != INT4OID)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("Third column must be type %s.",
  						   format_type_be(INT4OID))));
--- 1451,1464 ----
  	/* check that the types of the first two columns match */
  	if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("First two columns must be the same type.")));
  
  	/* check that the type of the third column is INT4 */
  	if (tupdesc->attrs[2]->atttypid != INT4OID)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("Third column must be type %s.",
  						   format_type_be(INT4OID))));
*************** validateConnectbyTupleDesc(TupleDesc tup
*** 1462,1481 ****
  	/* check that the type of the fourth column is TEXT if applicable */
  	if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("Fourth column must be type %s.",
  						   format_type_be(TEXTOID))));
  
  	/* check that the type of the fifth column is INT4 */
  	if (show_branch && show_serial && tupdesc->attrs[4]->atttypid != INT4OID)
! 		elog(ERROR, "query-specified return tuple not valid for Connectby: "
! 			 "fifth column must be type %s", format_type_be(INT4OID));
  
  	/* check that the type of the fifth column is INT4 */
  	if (!show_branch && show_serial && tupdesc->attrs[3]->atttypid != INT4OID)
! 		elog(ERROR, "query-specified return tuple not valid for Connectby: "
! 			 "fourth column must be type %s", format_type_be(INT4OID));
  
  	/* OK, the tupdesc is valid for our purposes */
  }
--- 1466,1491 ----
  	/* check that the type of the fourth column is TEXT if applicable */
  	if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("Fourth column must be type %s.",
  						   format_type_be(TEXTOID))));
  
  	/* check that the type of the fifth column is INT4 */
  	if (show_branch && show_serial && tupdesc->attrs[4]->atttypid != INT4OID)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
! 			  errmsg("query-specified return tuple not valid for Connectby: "
! 					 "fifth column must be type %s",
! 					 format_type_be(INT4OID))));
  
  	/* check that the type of the fifth column is INT4 */
  	if (!show_branch && show_serial && tupdesc->attrs[3]->atttypid != INT4OID)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
! 			  errmsg("query-specified return tuple not valid for Connectby: "
! 					 "fourth column must be type %s",
! 					 format_type_be(INT4OID))));
  
  	/* OK, the tupdesc is valid for our purposes */
  }
*************** compatConnectbyTupleDescs(TupleDesc ret_
*** 1496,1502 ****
  	 */
  	if (sql_tupdesc->natts < 2)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("Query must return at least two columns.")));
  
--- 1506,1512 ----
  	 */
  	if (sql_tupdesc->natts < 2)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("Query must return at least two columns.")));
  
*************** compatConnectbyTupleDescs(TupleDesc ret_
*** 1511,1517 ****
  	if (ret_atttypid != sql_atttypid ||
  		(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("SQL key field type %s does " \
  						   "not match return key field type %s.",
--- 1521,1527 ----
  	if (ret_atttypid != sql_atttypid ||
  		(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("SQL key field type %s does " \
  						   "not match return key field type %s.",
*************** compatConnectbyTupleDescs(TupleDesc ret_
*** 1525,1531 ****
  	if (ret_atttypid != sql_atttypid ||
  		(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("SQL parent key field type %s does " \
  						   "not match return parent key field type %s.",
--- 1535,1541 ----
  	if (ret_atttypid != sql_atttypid ||
  		(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("SQL parent key field type %s does " \
  						   "not match return parent key field type %s.",
*************** compatCrosstabTupleDescs(TupleDesc ret_t
*** 1556,1562 ****
  	sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
  	if (ret_atttypid != sql_atttypid)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
  				 errmsg("invalid return type"),
  				 errdetail("SQL rowid datatype does not match " \
  						   "return rowid datatype.")));
--- 1566,1572 ----
  	sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
  	if (ret_atttypid != sql_atttypid)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
  				 errmsg("invalid return type"),
  				 errdetail("SQL rowid datatype does not match " \
  						   "return rowid datatype.")));
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 8176b6a..180f529 100644
*** a/src/backend/access/common/reloptions.c
--- b/src/backend/access/common/reloptions.c
*************** allocate_reloption(bits32 kinds, int typ
*** 484,490 ****
  			size = sizeof(relopt_string);
  			break;
  		default:
! 			elog(ERROR, "unsupported option type");
  			return NULL;		/* keep compiler quiet */
  	}
  
--- 484,490 ----
  			size = sizeof(relopt_string);
  			break;
  		default:
! 			elog(ERROR, "unsupported reloption type %d", type);
  			return NULL;		/* keep compiler quiet */
  	}
  
*************** parse_one_reloption(relopt_value *option
*** 1016,1022 ****
  				parsed = parse_bool(value, &option->values.bool_val);
  				if (validate && !parsed)
  					ereport(ERROR,
! 					   (errmsg("invalid value for boolean option \"%s\": %s",
  							   option->gen->name, value)));
  			}
  			break;
--- 1016,1023 ----
  				parsed = parse_bool(value, &option->values.bool_val);
  				if (validate && !parsed)
  					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
! 						errmsg("invalid value for boolean option \"%s\": %s",
  							   option->gen->name, value)));
  			}
  			break;
*************** parse_one_reloption(relopt_value *option
*** 1027,1038 ****
  				parsed = parse_int(value, &option->values.int_val, 0, NULL);
  				if (validate && !parsed)
  					ereport(ERROR,
! 					   (errmsg("invalid value for integer option \"%s\": %s",
  							   option->gen->name, value)));
  				if (validate && (option->values.int_val < optint->min ||
  								 option->values.int_val > optint->max))
  					ereport(ERROR,
! 						  (errmsg("value %s out of bounds for option \"%s\"",
  								  value, option->gen->name),
  					 errdetail("Valid values are between \"%d\" and \"%d\".",
  							   optint->min, optint->max)));
--- 1028,1041 ----
  				parsed = parse_int(value, &option->values.int_val, 0, NULL);
  				if (validate && !parsed)
  					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
! 						errmsg("invalid value for integer option \"%s\": %s",
  							   option->gen->name, value)));
  				if (validate && (option->values.int_val < optint->min ||
  								 option->values.int_val > optint->max))
  					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
! 						   errmsg("value %s out of bounds for option \"%s\"",
  								  value, option->gen->name),
  					 errdetail("Valid values are between \"%d\" and \"%d\".",
  							   optint->min, optint->max)));
*************** parse_one_reloption(relopt_value *option
*** 1045,1056 ****
  				parsed = parse_real(value, &option->values.real_val);
  				if (validate && !parsed)
  					ereport(ERROR,
! 							(errmsg("invalid value for floating point option \"%s\": %s",
  									option->gen->name, value)));
  				if (validate && (option->values.real_val < optreal->min ||
  								 option->values.real_val > optreal->max))
  					ereport(ERROR,
! 						  (errmsg("value %s out of bounds for option \"%s\"",
  								  value, option->gen->name),
  					 errdetail("Valid values are between \"%f\" and \"%f\".",
  							   optreal->min, optreal->max)));
--- 1048,1061 ----
  				parsed = parse_real(value, &option->values.real_val);
  				if (validate && !parsed)
  					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
! 							 errmsg("invalid value for floating point option \"%s\": %s",
  									option->gen->name, value)));
  				if (validate && (option->values.real_val < optreal->min ||
  								 option->values.real_val > optreal->max))
  					ereport(ERROR,
! 							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
! 						   errmsg("value %s out of bounds for option \"%s\"",
  								  value, option->gen->name),
  					 errdetail("Valid values are between \"%f\" and \"%f\".",
  							   optreal->min, optreal->max)));
*************** fillRelOptions(void *rdopts, Size basesi
*** 1168,1174 ****
  						}
  						break;
  					default:
! 						elog(ERROR, "unrecognized reloption type %c",
  							 options[i].gen->type);
  						break;
  				}
--- 1173,1179 ----
  						}
  						break;
  					default:
! 						elog(ERROR, "unsupported reloption type %d",
  							 options[i].gen->type);
  						break;
  				}
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 050efdc..3701d8e 100644
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
*************** l1:
*** 2801,2807 ****
  	if (result == HeapTupleInvisible)
  	{
  		UnlockReleaseBuffer(buffer);
! 		elog(ERROR, "attempted to delete invisible tuple");
  	}
  	else if (result == HeapTupleBeingUpdated && wait)
  	{
--- 2801,2809 ----
  	if (result == HeapTupleInvisible)
  	{
  		UnlockReleaseBuffer(buffer);
! 		ereport(ERROR,
! 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
! 				 errmsg("attempted to delete invisible tuple")));
  	}
  	else if (result == HeapTupleBeingUpdated && wait)
  	{
*************** l2:
*** 3343,3349 ****
  	if (result == HeapTupleInvisible)
  	{
  		UnlockReleaseBuffer(buffer);
! 		elog(ERROR, "attempted to update invisible tuple");
  	}
  	else if (result == HeapTupleBeingUpdated && wait)
  	{
--- 3345,3353 ----
  	if (result == HeapTupleInvisible)
  	{
  		UnlockReleaseBuffer(buffer);
! 		ereport(ERROR,
! 				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
! 				 errmsg("attempted to update invisible tuple")));
  	}
  	else if (result == HeapTupleBeingUpdated && wait)
  	{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 47dd3ac..8db1b35 100644
*** a/src/backend/commands/copy.c
--- b/src/backend/commands/copy.c
*************** BeginCopy(bool is_from,
*** 1422,1430 ****
  		 * in any RLS clauses.
  		 *
  		 * When this happens, we are passed in the relid of the originally
! 		 * found relation (which we have locked).  As the planner will look
! 		 * up the relation again, we double-check here to make sure it found
! 		 * the same one that we have locked.
  		 */
  		if (queryRelId != InvalidOid)
  		{
--- 1422,1430 ----
  		 * in any RLS clauses.
  		 *
  		 * When this happens, we are passed in the relid of the originally
! 		 * found relation (which we have locked).  As the planner will look up
! 		 * the relation again, we double-check here to make sure it found the
! 		 * same one that we have locked.
  		 */
  		if (queryRelId != InvalidOid)
  		{
*************** ClosePipeToProgram(CopyState cstate)
*** 1603,1612 ****
  	pclose_rc = ClosePipeStream(cstate->copy_file);
  	if (pclose_rc == -1)
  		ereport(ERROR,
! 				(errmsg("could not close pipe to external command: %m")));
  	else if (pclose_rc != 0)
  		ereport(ERROR,
! 				(errmsg("program \"%s\" failed",
  						cstate->filename),
  				 errdetail_internal("%s", wait_result_to_str(pclose_rc))));
  }
--- 1603,1614 ----
  	pclose_rc = ClosePipeStream(cstate->copy_file);
  	if (pclose_rc == -1)
  		ereport(ERROR,
! 				(errcode_for_file_access(),
! 				 errmsg("could not close pipe to external command: %m")));
  	else if (pclose_rc != 0)
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("program \"%s\" failed",
  						cstate->filename),
  				 errdetail_internal("%s", wait_result_to_str(pclose_rc))));
  }
*************** BeginCopyTo(Relation rel,
*** 1703,1709 ****
  			cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_W);
  			if (cstate->copy_file == NULL)
  				ereport(ERROR,
! 						(errmsg("could not execute command \"%s\": %m",
  								cstate->filename)));
  		}
  		else
--- 1705,1712 ----
  			cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_W);
  			if (cstate->copy_file == NULL)
  				ereport(ERROR,
! 						(errcode_for_file_access(),
! 						 errmsg("could not execute command \"%s\": %m",
  								cstate->filename)));
  		}
  		else
*************** BeginCopyTo(Relation rel,
*** 1730,1736 ****
  								cstate->filename)));
  
  			if (fstat(fileno(cstate->copy_file), &st))
! 				elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
  
  			if (S_ISDIR(st.st_mode))
  				ereport(ERROR,
--- 1733,1742 ----
  								cstate->filename)));
  
  			if (fstat(fileno(cstate->copy_file), &st))
! 				ereport(ERROR,
! 						(errcode_for_file_access(),
! 						 errmsg("could not stat file \"%s\": %m",
! 								cstate->filename)));
  
  			if (S_ISDIR(st.st_mode))
  				ereport(ERROR,
*************** CopyFrom(CopyState cstate)
*** 2271,2283 ****
  	{
  		if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
  			ereport(ERROR,
! 					(ERRCODE_INVALID_TRANSACTION_STATE,
  					 errmsg("cannot perform FREEZE because of prior transaction activity")));
  
  		if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
  		 cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
  			ereport(ERROR,
! 					(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
  					 errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
  
  		hi_options |= HEAP_INSERT_FROZEN;
--- 2277,2289 ----
  	{
  		if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
  			ereport(ERROR,
! 					(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
  					 errmsg("cannot perform FREEZE because of prior transaction activity")));
  
  		if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
  		 cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
  			ereport(ERROR,
! 					(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
  					 errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
  
  		hi_options |= HEAP_INSERT_FROZEN;
*************** BeginCopyFrom(Relation rel,
*** 2737,2743 ****
  			cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_R);
  			if (cstate->copy_file == NULL)
  				ereport(ERROR,
! 						(errmsg("could not execute command \"%s\": %m",
  								cstate->filename)));
  		}
  		else
--- 2743,2750 ----
  			cstate->copy_file = OpenPipeStream(cstate->filename, PG_BINARY_R);
  			if (cstate->copy_file == NULL)
  				ereport(ERROR,
! 						(errcode_for_file_access(),
! 						 errmsg("could not execute command \"%s\": %m",
  								cstate->filename)));
  		}
  		else
*************** BeginCopyFrom(Relation rel,
*** 2752,2758 ****
  								cstate->filename)));
  
  			if (fstat(fileno(cstate->copy_file), &st))
! 				elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
  
  			if (S_ISDIR(st.st_mode))
  				ereport(ERROR,
--- 2759,2768 ----
  								cstate->filename)));
  
  			if (fstat(fileno(cstate->copy_file), &st))
! 				ereport(ERROR,
! 						(errcode_for_file_access(),
! 						 errmsg("could not stat file \"%s\": %m",
! 								cstate->filename)));
  
  			if (S_ISDIR(st.st_mode))
  				ereport(ERROR,
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index baf66f1..85b0483 100644
*** a/src/backend/commands/vacuum.c
--- b/src/backend/commands/vacuum.c
*************** vacuum(int options, RangeVar *relation, 
*** 180,186 ****
  	 * calls a hostile index expression that itself calls ANALYZE.
  	 */
  	if (in_vacuum)
! 		elog(ERROR, "%s cannot be executed from VACUUM or ANALYZE", stmttype);
  
  	/*
  	 * Send info about dead objects to the statistics collector, unless we are
--- 180,189 ----
  	 * calls a hostile index expression that itself calls ANALYZE.
  	 */
  	if (in_vacuum)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! 				 errmsg("%s cannot be executed from VACUUM or ANALYZE",
! 						stmttype)));
  
  	/*
  	 * Send info about dead objects to the statistics collector, unless we are
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 0f911f2..16bc8fa 100644
*** a/src/backend/executor/execQual.c
--- b/src/backend/executor/execQual.c
*************** ExecEvalScalarVar(ExprState *exprstate, 
*** 631,637 ****
  		{
  			if (variable->vartype != attr->atttypid)
  				ereport(ERROR,
! 						(errmsg("attribute %d has wrong type", attnum),
  						 errdetail("Table has type %s, but query expects %s.",
  								   format_type_be(attr->atttypid),
  								   format_type_be(variable->vartype))));
--- 631,638 ----
  		{
  			if (variable->vartype != attr->atttypid)
  				ereport(ERROR,
! 						(errcode(ERRCODE_DATATYPE_MISMATCH),
! 						 errmsg("attribute %d has wrong type", attnum),
  						 errdetail("Table has type %s, but query expects %s.",
  								   format_type_be(attr->atttypid),
  								   format_type_be(variable->vartype))));
*************** ExecEvalFieldSelect(FieldSelectState *fs
*** 4111,4117 ****
  	/* As in ExecEvalScalarVar, we should but can't check typmod */
  	if (fselect->resulttype != attr->atttypid)
  		ereport(ERROR,
! 				(errmsg("attribute %d has wrong type", fieldnum),
  				 errdetail("Table has type %s, but query expects %s.",
  						   format_type_be(attr->atttypid),
  						   format_type_be(fselect->resulttype))));
--- 4112,4119 ----
  	/* As in ExecEvalScalarVar, we should but can't check typmod */
  	if (fselect->resulttype != attr->atttypid)
  		ereport(ERROR,
! 				(errcode(ERRCODE_DATATYPE_MISMATCH),
! 				 errmsg("attribute %d has wrong type", fieldnum),
  				 errdetail("Table has type %s, but query expects %s.",
  						   format_type_be(attr->atttypid),
  						   format_type_be(fselect->resulttype))));
diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c
index ce1d9ab..ba4b482 100644
*** a/src/backend/utils/adt/txid.c
--- b/src/backend/utils/adt/txid.c
*************** parse_snapshot(const char *str)
*** 334,341 ****
  	return buf_finalize(buf);
  
  bad_format:
! 	elog(ERROR, "invalid input for txid_snapshot: \"%s\"", str_start);
! 	return NULL;
  }
  
  /*
--- 334,344 ----
  	return buf_finalize(buf);
  
  bad_format:
! 	ereport(ERROR,
! 			(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
! 			 errmsg("invalid input syntax for type txid_snapshot: \"%s\"",
! 					str_start)));
! 	return NULL;				/* keep compiler quiet */
  }
  
  /*
*************** txid_snapshot_recv(PG_FUNCTION_ARGS)
*** 526,533 ****
  	PG_RETURN_POINTER(snap);
  
  bad_format:
! 	elog(ERROR, "invalid snapshot data");
! 	return (Datum) NULL;
  }
  
  /*
--- 529,538 ----
  	PG_RETURN_POINTER(snap);
  
  bad_format:
! 	ereport(ERROR,
! 			(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
! 			 errmsg("invalid external txid_snapshot data")));
! 	PG_RETURN_POINTER(NULL);	/* keep compiler quiet */
  }
  
  /*
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 78baaac..ae0ba19 100644
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
*************** select_perl_context(bool trusted)
*** 640,647 ****
  		else
  			plperl_untrusted_init();
  #else
! 		elog(ERROR,
! 			 "cannot allocate multiple Perl interpreters on this platform");
  #endif
  	}
  
--- 640,648 ----
  		else
  			plperl_untrusted_init();
  #else
! 		errmsg(ERROR,
! 			   (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! 				errmsg("cannot allocate multiple Perl interpreters on this platform")));
  #endif
  	}
  
*************** select_perl_context(bool trusted)
*** 660,666 ****
  	eval_pv("PostgreSQL::InServer::SPI::bootstrap()", FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  		errcontext("while executing PostgreSQL::InServer::SPI::bootstrap")));
  
  	/* Fully initialized, so mark the hashtable entry valid */
--- 661,668 ----
  	eval_pv("PostgreSQL::InServer::SPI::bootstrap()", FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  		errcontext("while executing PostgreSQL::InServer::SPI::bootstrap")));
  
  	/* Fully initialized, so mark the hashtable entry valid */
*************** plperl_init_interp(void)
*** 834,845 ****
  	if (perl_parse(plperl, plperl_init_shared_libs,
  				   nargs, embedding, NULL) != 0)
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while parsing Perl initialization")));
  
  	if (perl_run(plperl) != 0)
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while running Perl initialization")));
  
  #ifdef PLPERL_RESTORE_LOCALE
--- 836,849 ----
  	if (perl_parse(plperl, plperl_init_shared_libs,
  				   nargs, embedding, NULL) != 0)
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while parsing Perl initialization")));
  
  	if (perl_run(plperl) != 0)
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while running Perl initialization")));
  
  #ifdef PLPERL_RESTORE_LOCALE
*************** plperl_trusted_init(void)
*** 952,958 ****
  	eval_pv(PLC_TRUSTED, FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while executing PLC_TRUSTED")));
  
  	/*
--- 956,963 ----
  	eval_pv(PLC_TRUSTED, FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while executing PLC_TRUSTED")));
  
  	/*
*************** plperl_trusted_init(void)
*** 963,969 ****
  	eval_pv("my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while executing utf8fix")));
  
  	/*
--- 968,975 ----
  	eval_pv("my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE);
  	if (SvTRUE(ERRSV))
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  				 errcontext("while executing utf8fix")));
  
  	/*
*************** plperl_trusted_init(void)
*** 1002,1012 ****
  	if (plperl_on_plperl_init && *plperl_on_plperl_init)
  	{
  		eval_pv(plperl_on_plperl_init, FALSE);
  		if (SvTRUE(ERRSV))
  			ereport(ERROR,
! 					(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  					 errcontext("while executing plperl.on_plperl_init")));
- 
  	}
  }
  
--- 1008,1019 ----
  	if (plperl_on_plperl_init && *plperl_on_plperl_init)
  	{
  		eval_pv(plperl_on_plperl_init, FALSE);
+ 		/* XXX need to find a way to determine a better errcode here */
  		if (SvTRUE(ERRSV))
  			ereport(ERROR,
! 					(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 					 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  					 errcontext("while executing plperl.on_plperl_init")));
  	}
  }
  
*************** plperl_untrusted_init(void)
*** 1025,1031 ****
  		eval_pv(plperl_on_plperlu_init, FALSE);
  		if (SvTRUE(ERRSV))
  			ereport(ERROR,
! 					(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  					 errcontext("while executing plperl.on_plperlu_init")));
  	}
  }
--- 1032,1039 ----
  		eval_pv(plperl_on_plperlu_init, FALSE);
  		if (SvTRUE(ERRSV))
  			ereport(ERROR,
! 					(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 					 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))),
  					 errcontext("while executing plperl.on_plperlu_init")));
  	}
  }
*************** plperl_sv_to_literal(SV *sv, char *fqtyp
*** 1382,1388 ****
  				isnull;
  
  	if (!OidIsValid(typid))
! 		elog(ERROR, "lookup failed for type %s", fqtypename);
  
  	datum = plperl_sv_to_datum(sv,
  							   typid, -1,
--- 1390,1398 ----
  				isnull;
  
  	if (!OidIsValid(typid))
! 		ereport(ERROR,
! 				(errcode(ERRCODE_UNDEFINED_OBJECT),
! 				 errmsg("lookup failed for type %s", fqtypename)));
  
  	datum = plperl_sv_to_datum(sv,
  							   typid, -1,
*************** plperl_create_sub(plperl_proc_desc *prod
*** 2059,2065 ****
  
  	if (!subref)
  		ereport(ERROR,
! 		(errmsg("didn't get a CODE reference from compiling function \"%s\"",
  				prodesc->proname)));
  
  	prodesc->reference = subref;
--- 2069,2076 ----
  
  	if (!subref)
  		ereport(ERROR,
! 				(errcode(ERRCODE_SYNTAX_ERROR),
! 		 errmsg("didn't get a CODE reference from compiling function \"%s\"",
  				prodesc->proname)));
  
  	prodesc->reference = subref;
*************** plperl_call_perl_func(plperl_proc_desc *
*** 2147,2153 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		elog(ERROR, "didn't get a return item from function");
  	}
  
  	if (SvTRUE(ERRSV))
--- 2158,2166 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("didn't get a return item from function")));
  	}
  
  	if (SvTRUE(ERRSV))
*************** plperl_call_perl_func(plperl_proc_desc *
*** 2156,2164 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to assign an errcode here */
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
--- 2169,2178 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to determine a better errcode here */
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
*************** plperl_call_perl_trigger_func(plperl_pro
*** 2187,2193 ****
  
  	TDsv = get_sv("main::_TD", 0);
  	if (!TDsv)
! 		elog(ERROR, "couldn't fetch $_TD");
  
  	save_item(TDsv);			/* local $_TD */
  	sv_setsv(TDsv, td);
--- 2201,2209 ----
  
  	TDsv = get_sv("main::_TD", 0);
  	if (!TDsv)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("couldn't fetch $_TD")));
  
  	save_item(TDsv);			/* local $_TD */
  	sv_setsv(TDsv, td);
*************** plperl_call_perl_trigger_func(plperl_pro
*** 2209,2215 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		elog(ERROR, "didn't get a return item from trigger function");
  	}
  
  	if (SvTRUE(ERRSV))
--- 2225,2233 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("didn't get a return item from trigger function")));
  	}
  
  	if (SvTRUE(ERRSV))
*************** plperl_call_perl_trigger_func(plperl_pro
*** 2218,2226 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to assign an errcode here */
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
--- 2236,2245 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to determine a better errcode here */
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
*************** plperl_call_perl_event_trigger_func(plpe
*** 2248,2254 ****
  
  	TDsv = get_sv("main::_TD", 0);
  	if (!TDsv)
! 		elog(ERROR, "couldn't fetch $_TD");
  
  	save_item(TDsv);			/* local $_TD */
  	sv_setsv(TDsv, td);
--- 2267,2275 ----
  
  	TDsv = get_sv("main::_TD", 0);
  	if (!TDsv)
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("couldn't fetch $_TD")));
  
  	save_item(TDsv);			/* local $_TD */
  	sv_setsv(TDsv, td);
*************** plperl_call_perl_event_trigger_func(plpe
*** 2266,2272 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		elog(ERROR, "didn't get a return item from trigger function");
  	}
  
  	if (SvTRUE(ERRSV))
--- 2287,2295 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("didn't get a return item from trigger function")));
  	}
  
  	if (SvTRUE(ERRSV))
*************** plperl_call_perl_event_trigger_func(plpe
*** 2275,2283 ****
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to assign an errcode here */
  		ereport(ERROR,
! 				(errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
--- 2298,2307 ----
  		PUTBACK;
  		FREETMPS;
  		LEAVE;
! 		/* XXX need to find a way to determine a better errcode here */
  		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV)))));
  	}
  
  	retval = newSVsv(POPs);
diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c
index 461d68c..15406d6 100644
*** a/src/pl/plpython/plpy_elog.c
--- b/src/pl/plpython/plpy_elog.c
*************** PLy_elog(int elevel, const char *fmt,...
*** 97,103 ****
  	PG_TRY();
  	{
  		ereport(elevel,
! 				(errcode(sqlerrcode ? sqlerrcode : ERRCODE_INTERNAL_ERROR),
  			  errmsg_internal("%s", primary ? primary : "no exception data"),
  				 (detail) ? errdetail_internal("%s", detail) : 0,
  				 (tb_depth > 0 && tbmsg) ? errcontext("%s", tbmsg) : 0,
--- 97,103 ----
  	PG_TRY();
  	{
  		ereport(elevel,
! 				(errcode(sqlerrcode ? sqlerrcode : ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
  			  errmsg_internal("%s", primary ? primary : "no exception data"),
  				 (detail) ? errdetail_internal("%s", detail) : 0,
  				 (tb_depth > 0 && tbmsg) ? errcontext("%s", tbmsg) : 0,
diff --git a/src/pl/plpython/plpy_exec.c b/src/pl/plpython/plpy_exec.c
index 8c525c9..3ccebe4 100644
*** a/src/pl/plpython/plpy_exec.c
--- b/src/pl/plpython/plpy_exec.c
*************** PLy_modify_tuple(PLyProcedure *proc, PyO
*** 662,672 ****
  	{
  		if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL)
  			ereport(ERROR,
! 					(errmsg("TD[\"new\"] deleted, cannot modify row")));
  		Py_INCREF(plntup);
  		if (!PyDict_Check(plntup))
  			ereport(ERROR,
! 					(errmsg("TD[\"new\"] is not a dictionary")));
  
  		plkeys = PyDict_Keys(plntup);
  		natts = PyList_Size(plkeys);
--- 662,674 ----
  	{
  		if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL)
  			ereport(ERROR,
! 					(errcode(ERRCODE_UNDEFINED_OBJECT),
! 					 errmsg("TD[\"new\"] deleted, cannot modify row")));
  		Py_INCREF(plntup);
  		if (!PyDict_Check(plntup))
  			ereport(ERROR,
! 					(errcode(ERRCODE_DATATYPE_MISMATCH),
! 					 errmsg("TD[\"new\"] is not a dictionary")));
  
  		plkeys = PyDict_Keys(plntup);
  		natts = PyList_Size(plkeys);
*************** PLy_modify_tuple(PLyProcedure *proc, PyO
*** 690,702 ****
  			else
  			{
  				ereport(ERROR,
! 						(errmsg("TD[\"new\"] dictionary key at ordinal position %d is not a string", i)));
  				plattstr = NULL;	/* keep compiler quiet */
  			}
  			attn = SPI_fnumber(tupdesc, plattstr);
  			if (attn == SPI_ERROR_NOATTRIBUTE)
  				ereport(ERROR,
! 						(errmsg("key \"%s\" found in TD[\"new\"] does not exist as a column in the triggering row",
  								plattstr)));
  			atti = attn - 1;
  
--- 692,706 ----
  			else
  			{
  				ereport(ERROR,
! 						(errcode(ERRCODE_DATATYPE_MISMATCH),
! 						 errmsg("TD[\"new\"] dictionary key at ordinal position %d is not a string", i)));
  				plattstr = NULL;	/* keep compiler quiet */
  			}
  			attn = SPI_fnumber(tupdesc, plattstr);
  			if (attn == SPI_ERROR_NOATTRIBUTE)
  				ereport(ERROR,
! 						(errcode(ERRCODE_UNDEFINED_COLUMN),
! 						 errmsg("key \"%s\" found in TD[\"new\"] does not exist as a column in the triggering row",
  								plattstr)));
  			atti = attn - 1;
  
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 48a3206..edfda59 100644
*** a/src/pl/tcl/pltcl.c
--- b/src/pl/tcl/pltcl.c
*************** pltcl_init_load_unknown(Tcl_Interp *inte
*** 551,557 ****
  	if (SPI_processed == 0)
  	{
  		SPI_freetuptable(SPI_tuptable);
! 		elog(WARNING, "module \"unknown\" not found in pltcl_modules");
  		relation_close(pmrel, AccessShareLock);
  		return;
  	}
--- 551,558 ----
  	if (SPI_processed == 0)
  	{
  		SPI_freetuptable(SPI_tuptable);
! 		ereport(WARNING,
! 				(errmsg("module \"unknown\" not found in pltcl_modules")));
  		relation_close(pmrel, AccessShareLock);
  		return;
  	}
*************** pltcl_init_load_unknown(Tcl_Interp *inte
*** 585,592 ****
  	if (tcl_rc != TCL_OK)
  	{
  		UTF_BEGIN;
! 		elog(ERROR, "could not load module \"unknown\": %s",
! 			 UTF_U2E(Tcl_GetStringResult(interp)));
  		UTF_END;
  	}
  
--- 586,595 ----
  	if (tcl_rc != TCL_OK)
  	{
  		UTF_BEGIN;
! 		ereport(ERROR,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("could not load module \"unknown\": %s",
! 						UTF_U2E(Tcl_GetStringResult(interp)))));
  		UTF_END;
  	}
  
*************** pltcl_trigger_handler(PG_FUNCTION_ARGS, 
*** 1039,1046 ****
  					  &ret_numvals, &ret_values) != TCL_OK)
  	{
  		UTF_BEGIN;
! 		elog(ERROR, "could not split return value from trigger: %s",
! 			 UTF_U2E(Tcl_GetStringResult(interp)));
  		UTF_END;
  	}
  
--- 1042,1051 ----
  					  &ret_numvals, &ret_values) != TCL_OK)
  	{
  		UTF_BEGIN;
! 		ereport(ERROR,
! 				(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
! 				 errmsg("could not split return value from trigger: %s",
! 						UTF_U2E(Tcl_GetStringResult(interp)))));
  		UTF_END;
  	}
  
*************** pltcl_trigger_handler(PG_FUNCTION_ARGS, 
*** 1048,1054 ****
  	PG_TRY();
  	{
  		if (ret_numvals % 2 != 0)
! 			elog(ERROR, "invalid return list from trigger - must have even # of elements");
  
  		modattrs = (int *) palloc(tupdesc->natts * sizeof(int));
  		modvalues = (Datum *) palloc(tupdesc->natts * sizeof(Datum));
--- 1053,1061 ----
  	PG_TRY();
  	{
  		if (ret_numvals % 2 != 0)
! 			ereport(ERROR,
! 					(errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
! 					 errmsg("invalid return list from trigger - must have even # of elements")));
  
  		modattrs = (int *) palloc(tupdesc->natts * sizeof(int));
  		modvalues = (Datum *) palloc(tupdesc->natts * sizeof(Datum));
*************** pltcl_trigger_handler(PG_FUNCTION_ARGS, 
*** 1082,1090 ****
  			 ************************************************************/
  			attnum = SPI_fnumber(tupdesc, ret_name);
  			if (attnum == SPI_ERROR_NOATTRIBUTE)
! 				elog(ERROR, "invalid attribute \"%s\"", ret_name);
  			if (attnum <= 0)
! 				elog(ERROR, "cannot set system attribute \"%s\"", ret_name);
  
  			/************************************************************
  			 * Ignore dropped columns
--- 1089,1103 ----
  			 ************************************************************/
  			attnum = SPI_fnumber(tupdesc, ret_name);
  			if (attnum == SPI_ERROR_NOATTRIBUTE)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_UNDEFINED_COLUMN),
! 						 errmsg("unrecognized attribute \"%s\"",
! 								ret_name)));
  			if (attnum <= 0)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! 						 errmsg("cannot set system attribute \"%s\"",
! 								ret_name)));
  
  			/************************************************************
  			 * Ignore dropped columns
*************** throw_tcl_error(Tcl_Interp *interp, cons
*** 1205,1211 ****
  	econtext = UTF_U2E((char *) Tcl_GetVar(interp, "errorInfo",
  										   TCL_GLOBAL_ONLY));
  	ereport(ERROR,
! 			(errmsg("%s", emsg),
  			 errcontext("%s\nin PL/Tcl function \"%s\"",
  						econtext, proname)));
  	UTF_END;
--- 1218,1225 ----
  	econtext = UTF_U2E((char *) Tcl_GetVar(interp, "errorInfo",
  										   TCL_GLOBAL_ONLY));
  	ereport(ERROR,
! 			(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 			 errmsg("%s", emsg),
  			 errcontext("%s\nin PL/Tcl function \"%s\"",
  						econtext, proname)));
  	UTF_END;
*************** compile_pltcl_function(Oid fn_oid, Oid t
*** 1545,1552 ****
  			free(prodesc->internal_proname);
  			free(prodesc);
  			UTF_BEGIN;
! 			elog(ERROR, "could not create internal procedure \"%s\": %s",
! 				 internal_proname, UTF_U2E(Tcl_GetStringResult(interp)));
  			UTF_END;
  		}
  
--- 1559,1569 ----
  			free(prodesc->internal_proname);
  			free(prodesc);
  			UTF_BEGIN;
! 			ereport(ERROR,
! 					(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 					 errmsg("could not create internal procedure \"%s\": %s",
! 							internal_proname,
! 							UTF_U2E(Tcl_GetStringResult(interp)))));
  			UTF_END;
  		}
  
*************** pltcl_elog(ClientData cdata, Tcl_Interp 
*** 1614,1623 ****
  	}
  
  	/*
! 	 * For non-error messages, just pass 'em to elog().  We do not expect that
! 	 * this will fail, but just on the off chance it does, report the error
! 	 * back to Tcl.  Note we are assuming that elog() can't have any internal
! 	 * failures that are so bad as to require a transaction abort.
  	 *
  	 * This path is also used for FATAL errors, which aren't going to come
  	 * back to us at all.
--- 1631,1640 ----
  	}
  
  	/*
! 	 * For non-error messages, just pass 'em to ereport().  We do not expect
! 	 * that this will fail, but just on the off chance it does, report the
! 	 * error back to Tcl.  Note we are assuming that ereport() can't have any
! 	 * internal failures that are so bad as to require a transaction abort.
  	 *
  	 * This path is also used for FATAL errors, which aren't going to come
  	 * back to us at all.
*************** pltcl_elog(ClientData cdata, Tcl_Interp 
*** 1626,1632 ****
  	PG_TRY();
  	{
  		UTF_BEGIN;
! 		elog(level, "%s", UTF_U2E(argv[2]));
  		UTF_END;
  	}
  	PG_CATCH();
--- 1643,1651 ----
  	PG_TRY();
  	{
  		UTF_BEGIN;
! 		ereport(level,
! 				(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
! 				 errmsg("%s", UTF_U2E(argv[2]))));
  		UTF_END;
  	}
  	PG_CATCH();
diff --git a/src/test/regress/expected/txid.out b/src/test/regress/expected/txid.out
index 7750b7b..ddd217e 100644
*** a/src/test/regress/expected/txid.out
--- b/src/test/regress/expected/txid.out
*************** select '12:16:14,14'::txid_snapshot;
*** 20,38 ****
  
  -- errors
  select '31:12:'::txid_snapshot;
! ERROR:  invalid input for txid_snapshot: "31:12:"
  LINE 1: select '31:12:'::txid_snapshot;
                 ^
  select '0:1:'::txid_snapshot;
! ERROR:  invalid input for txid_snapshot: "0:1:"
  LINE 1: select '0:1:'::txid_snapshot;
                 ^
  select '12:13:0'::txid_snapshot;
! ERROR:  invalid input for txid_snapshot: "12:13:0"
  LINE 1: select '12:13:0'::txid_snapshot;
                 ^
  select '12:16:14,13'::txid_snapshot;
! ERROR:  invalid input for txid_snapshot: "12:16:14,13"
  LINE 1: select '12:16:14,13'::txid_snapshot;
                 ^
  create temp table snapshot_test (
--- 20,38 ----
  
  -- errors
  select '31:12:'::txid_snapshot;
! ERROR:  invalid input syntax for type txid_snapshot: "31:12:"
  LINE 1: select '31:12:'::txid_snapshot;
                 ^
  select '0:1:'::txid_snapshot;
! ERROR:  invalid input syntax for type txid_snapshot: "0:1:"
  LINE 1: select '0:1:'::txid_snapshot;
                 ^
  select '12:13:0'::txid_snapshot;
! ERROR:  invalid input syntax for type txid_snapshot: "12:13:0"
  LINE 1: select '12:13:0'::txid_snapshot;
                 ^
  select '12:16:14,13'::txid_snapshot;
! ERROR:  invalid input syntax for type txid_snapshot: "12:16:14,13"
  LINE 1: select '12:16:14,13'::txid_snapshot;
                 ^
  create temp table snapshot_test (
*************** SELECT txid_snapshot '1:9223372036854775
*** 235,240 ****
  (1 row)
  
  SELECT txid_snapshot '1:9223372036854775808:3';
! ERROR:  invalid input for txid_snapshot: "1:9223372036854775808:3"
  LINE 1: SELECT txid_snapshot '1:9223372036854775808:3';
                               ^
--- 235,240 ----
  (1 row)
  
  SELECT txid_snapshot '1:9223372036854775808:3';
! ERROR:  invalid input syntax for type txid_snapshot: "1:9223372036854775808:3"
  LINE 1: SELECT txid_snapshot '1:9223372036854775808:3';
                               ^
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index bd31a3d..476975f 100644
*** a/src/test/regress/regress.c
--- b/src/test/regress/regress.c
*************** ttdummy(PG_FUNCTION_ARGS)
*** 549,556 ****
  			elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
  
  		if (oldon != newon || oldoff != newoff)
! 			elog(ERROR, "ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
! 				 relname, args[0], args[1]);
  
  		if (newoff != TTDUMMY_INFINITY)
  		{
--- 549,558 ----
  			elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
  
  		if (oldon != newon || oldoff != newoff)
! 			ereport(ERROR,
! 					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
! 					 errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
! 							relname, args[0], args[1])));
  
  		if (newoff != TTDUMMY_INFINITY)
  		{
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to