diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index 3ed9b5c..a5e5d12 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -393,7 +393,8 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
 										RelationGetRelationName(rel)),
 								 errdetail("Key %s already exists.",
 										   BuildIndexValueDescription(rel,
-														  values, isnull))));
+														  values, isnull)),
+								 constraint_relation_error(rel)));
 					}
 				}
 				else if (all_dead)
@@ -455,7 +456,8 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
 				(errcode(ERRCODE_INTERNAL_ERROR),
 				 errmsg("failed to re-find tuple within index \"%s\"",
 						RelationGetRelationName(rel)),
-		errhint("This may be because of a non-immutable index expression.")));
+		errhint("This may be because of a non-immutable index expression."),
+				 relation_error(rel)));
 
 	if (nbuf != InvalidBuffer)
 		_bt_relbuf(rel, nbuf);
@@ -533,7 +535,8 @@ _bt_findinsertloc(Relation rel,
 				   RelationGetRelationName(rel)),
 		errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
 				"Consider a function index of an MD5 hash of the value, "
-				"or use full text indexing.")));
+				"or use full text indexing."),
+				relation_error(rel)));
 
 	/*----------
 	 * If we will need to split the page to put the item on this page,
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index fbb36fa..ef9740d 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1522,7 +1522,9 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
 						 errmsg("null value in column \"%s\" violates not-null constraint",
 						NameStr(rel->rd_att->attrs[attrChk - 1]->attname)),
 						 errdetail("Failing row contains %s.",
-								   ExecBuildSlotValueDescription(slot, 64))));
+								   ExecBuildSlotValueDescription(slot, 64)),
+						 relation_column_error(rel, NameStr(rel->rd_att->attrs[attrChk - 1]->attname)),
+						 constraint_error(rel, "not_null_violation")));
 		}
 	}
 
@@ -1536,7 +1538,9 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
 					 errmsg("new row for relation \"%s\" violates check constraint \"%s\"",
 							RelationGetRelationName(rel), failed),
 					 errdetail("Failing row contains %s.",
-							   ExecBuildSlotValueDescription(slot, 64))));
+							   ExecBuildSlotValueDescription(slot, 64)),
+					 relation_error(rel),
+					 constraint_error(rel, failed)));
 	}
 }
 
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 40cd5ce..153ea1a 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -1304,14 +1304,16 @@ retry:
 					 errmsg("could not create exclusion constraint \"%s\"",
 							RelationGetRelationName(index)),
 					 errdetail("Key %s conflicts with key %s.",
-							   error_new, error_existing)));
+							   error_new, error_existing),
+					 constraint_relation_error(index)));
 		else
 			ereport(ERROR,
 					(errcode(ERRCODE_EXCLUSION_VIOLATION),
 					 errmsg("conflicting key value violates exclusion constraint \"%s\"",
 							RelationGetRelationName(index)),
 					 errdetail("Key %s conflicts with existing key %s.",
-							   error_new, error_existing)));
+							   error_new, error_existing),
+					 constraint_relation_error(index)));
 	}
 
 	index_endscan(index_scan);
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index dd58f4e..c8f13b1 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -409,7 +409,9 @@ RI_FKey_check(PG_FUNCTION_ARGS)
 							 errmsg("insert or update on table \"%s\" violates foreign key constraint \"%s\"",
 							  RelationGetRelationName(trigdata->tg_relation),
 									NameStr(riinfo.conname)),
-							 errdetail("MATCH FULL does not allow mixing of null and nonnull key values.")));
+							 errdetail("MATCH FULL does not allow mixing of null and nonnull key values."),
+							 relation_error(trigdata->tg_relation),
+							 constraint_error(trigdata->tg_relation, NameStr(riinfo.conname))));
 					heap_close(pk_rel, RowShareLock);
 					return PointerGetDatum(NULL);
 
@@ -2841,7 +2843,9 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
 						 errmsg("insert or update on table \"%s\" violates foreign key constraint \"%s\"",
 								RelationGetRelationName(fk_rel),
 								constrname),
-						 errdetail("MATCH FULL does not allow mixing of null and nonnull key values.")));
+						 errdetail("MATCH FULL does not allow mixing of null and nonnull key values."),
+						 relation_error(fk_rel),
+						 constraint_error(fk_rel, constrname)));
 		}
 
 		/*
@@ -3536,7 +3540,9 @@ ri_ReportViolation(RI_QueryKey *qkey, const char *constrname,
 				 errmsg("insert or update on table \"%s\" violates foreign key constraint \"%s\"",
 						RelationGetRelationName(fk_rel), constrname),
 				 errdetail("No rows were found in \"%s\".",
-						   RelationGetRelationName(pk_rel))));
+						   RelationGetRelationName(pk_rel)),
+				 relation_error(fk_rel),
+				 constraint_error(fk_rel, constrname)));
 	}
 
 	/* Get printable versions of the keys involved */
@@ -3569,7 +3575,9 @@ ri_ReportViolation(RI_QueryKey *qkey, const char *constrname,
 						RelationGetRelationName(fk_rel), constrname),
 				 errdetail("Key (%s)=(%s) is not present in table \"%s\".",
 						   key_names.data, key_values.data,
-						   RelationGetRelationName(pk_rel))));
+						   RelationGetRelationName(pk_rel)),
+				 relation_error(fk_rel),
+				 constraint_error(fk_rel, constrname)));
 	else
 		ereport(ERROR,
 				(errcode(ERRCODE_FOREIGN_KEY_VIOLATION),
@@ -3578,7 +3586,9 @@ ri_ReportViolation(RI_QueryKey *qkey, const char *constrname,
 						constrname, RelationGetRelationName(fk_rel)),
 			errdetail("Key (%s)=(%s) is still referenced from table \"%s\".",
 					  key_names.data, key_values.data,
-					  RelationGetRelationName(fk_rel))));
+					  RelationGetRelationName(fk_rel)),
+				 relation_error(pk_rel),
+				 constraint_error(fk_rel, constrname)));
 }
 
 /* ----------
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 44dab82..d9fbdf0 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -2924,3 +2924,18 @@ get_range_subtype(Oid rangeOid)
 	else
 		return InvalidOid;
 }
+
+/*
+ * Sets column_name, table_name and schema_name in ErrorData
+ */
+inline int
+rel_column_error(Oid table_oid, const char *colname)
+{
+	if (colname != NULL)
+		erritem(PG_DIAG_COLUMN_NAME, colname);
+
+	erritem(PG_DIAG_TABLE_NAME, get_rel_name(table_oid));
+	erritem(PG_DIAG_SCHEMA_NAME, get_namespace_name(get_rel_namespace(table_oid)));
+
+	return 0;
+}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 7f0e20e..4d3fd87 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -4623,3 +4623,51 @@ unlink_initfile(const char *initfilename)
 			elog(LOG, "could not remove cache file \"%s\": %m", initfilename);
 	}
 }
+
+/*
+ * Sets column_name, table_name and schema_name in ErrorData related to relation
+ */
+inline int
+relation_column_error(Relation rel, const char *colname)
+{
+	if (colname != NULL)
+		erritem(PG_DIAG_COLUMN_NAME, colname);
+
+	erritem(PG_DIAG_TABLE_NAME, RelationGetRelationName(rel));
+	erritem(PG_DIAG_SCHEMA_NAME, get_namespace_name(RelationGetNamespace(rel)));
+
+	return 0;
+}
+
+/*
+ * Sets column_name, table_name and schema_name in ErrorData related to relation
+ */
+inline int
+relation_error(Relation rel)
+{
+	erritem(PG_DIAG_TABLE_NAME, RelationGetRelationName(rel));
+	erritem(PG_DIAG_SCHEMA_NAME, get_namespace_name(RelationGetNamespace(rel)));
+
+	return 0;
+}
+
+/*
+ * Sets constraint_name and constraint_schema in ErrorData
+ */
+inline int
+constraint_error(Relation rel, const char *cname)
+{
+	erritem(PG_DIAG_CONSTRAINT_NAME, cname);
+	erritem(PG_DIAG_CONSTRAINT_SCHEMA, get_namespace_name(RelationGetNamespace(rel)));
+
+	return 0;
+}
+
+inline int
+constraint_relation_error(Relation rel)
+{
+	erritem(PG_DIAG_CONSTRAINT_NAME, RelationGetRelationName(rel));
+	erritem(PG_DIAG_CONSTRAINT_SCHEMA, get_namespace_name(RelationGetNamespace(rel)));
+
+	return 0;
+}
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 65c28a7..77aa9b9 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -477,6 +477,24 @@ errfinish(int dummy,...)
 		pfree(edata->context);
 	if (edata->internalquery)
 		pfree(edata->internalquery);
+	if (edata->column_name)
+		pfree(edata->column_name);
+	if (edata->table_name)
+		pfree(edata->table_name);
+	if (edata->schema_name)
+		pfree(edata->schema_name);
+	if (edata->constraint_name)
+		pfree(edata->constraint_name);
+	if (edata->constraint_schema)
+		pfree(edata->constraint_schema);
+	if (edata->routine_name)
+		pfree(edata->routine_name);
+	if (edata->routine_schema)
+		pfree(edata->routine_schema);
+	if (edata->trigger_name)
+		pfree(edata->trigger_name);
+	if (edata->trigger_schema)
+		pfree(edata->trigger_schema);
 
 	errordata_stack_depth--;
 
@@ -1078,6 +1096,98 @@ internalerrquery(const char *query)
 	return 0;					/* return value does not matter */
 }
 
+static inline void
+set_field(char **ptr, const char *str, bool overwrite)
+{
+	if (*ptr != NULL)
+	{
+		/*
+		 * for some cases like ROUTINE_NAME, ROUTINE_SCHEMA we would
+		 * to get the most older value.
+		 */
+		if (!overwrite)
+			return;
+
+		pfree(*ptr);
+		*ptr = NULL;
+	}
+
+	if (str != NULL)
+		*ptr = MemoryContextStrdup(ErrorContext, str);
+}
+
+/*
+ * erritem -- generic setting of ErrorData string fields
+ */
+int
+erritem(int field, const char *str)
+{
+	ErrorData  *edata = &errordata[errordata_stack_depth];
+
+	/* we don't bother incrementing recursion_depth */
+	CHECK_STACK_DEPTH();
+
+	switch (field)
+	{
+		case PG_DIAG_MESSAGE_PRIMARY:
+			set_field(&edata->message, str, true);
+			break;
+
+		case PG_DIAG_MESSAGE_DETAIL:
+			set_field(&edata->detail, str, true);
+			break;
+
+		case PG_DIAG_MESSAGE_HINT:
+			set_field(&edata->hint, str, true);
+			break;
+
+		case PG_DIAG_CONTEXT:
+			set_field(&edata->context, str, true);
+			break;
+
+		case PG_DIAG_COLUMN_NAME:
+			set_field(&edata->column_name, str, true);
+			break;
+
+		case PG_DIAG_TABLE_NAME:
+			set_field(&edata->table_name, str, true);
+			break;
+
+		case PG_DIAG_SCHEMA_NAME:
+			set_field(&edata->schema_name, str, true);
+			break;
+
+		case PG_DIAG_CONSTRAINT_NAME:
+			set_field(&edata->constraint_name, str, true);
+			break;
+
+		case PG_DIAG_CONSTRAINT_SCHEMA:
+			set_field(&edata->constraint_schema, str, true);
+			break;
+
+		case PG_DIAG_ROUTINE_NAME:
+			set_field(&edata->routine_name, str, false);
+			break;
+
+		case PG_DIAG_ROUTINE_SCHEMA:
+			set_field(&edata->routine_schema, str, false);
+			break;
+
+		case PG_DIAG_TRIGGER_NAME:
+			set_field(&edata->trigger_name, str, false);
+			break;
+
+		case PG_DIAG_TRIGGER_SCHEMA:
+			set_field(&edata->trigger_schema, str, false);
+			break;
+
+		default:
+			elog(ERROR, "unknown ErrorData field id %d", field);
+	}
+
+	return 0;					/* return value does not matter */
+}
+
 /*
  * geterrcode --- return the currently set SQLSTATE error code
  *
@@ -1352,6 +1462,24 @@ CopyErrorData(void)
 		newedata->context = pstrdup(newedata->context);
 	if (newedata->internalquery)
 		newedata->internalquery = pstrdup(newedata->internalquery);
+	if (newedata->column_name)
+		newedata->column_name = pstrdup(newedata->column_name);
+	if (newedata->table_name)
+		newedata->table_name = pstrdup(newedata->table_name);
+	if (newedata->schema_name)
+		newedata->schema_name = pstrdup(newedata->schema_name);
+	if (newedata->constraint_name)
+		newedata->constraint_name = pstrdup(newedata->constraint_name);
+	if (newedata->constraint_schema)
+		newedata->constraint_schema = pstrdup(newedata->constraint_schema);
+	if (newedata->routine_name)
+		newedata->routine_name = pstrdup(newedata->routine_name);
+	if (newedata->routine_schema)
+		newedata->routine_schema = pstrdup(newedata->routine_schema);
+	if (newedata->trigger_name)
+		newedata->trigger_name = pstrdup(newedata->trigger_name);
+	if (newedata->trigger_schema)
+		newedata->trigger_schema = pstrdup(newedata->trigger_schema);
 
 	return newedata;
 }
@@ -1377,6 +1505,24 @@ FreeErrorData(ErrorData *edata)
 		pfree(edata->context);
 	if (edata->internalquery)
 		pfree(edata->internalquery);
+	if (edata->column_name)
+		pfree(edata->column_name);
+	if (edata->table_name)
+		pfree(edata->table_name);
+	if (edata->schema_name)
+		pfree(edata->schema_name);
+	if (edata->constraint_name)
+		pfree(edata->constraint_name);
+	if (edata->constraint_schema)
+		pfree(edata->constraint_schema);
+	if (edata->routine_name)
+		pfree(edata->routine_name);
+	if (edata->routine_schema)
+		pfree(edata->routine_schema);
+	if (edata->trigger_name)
+		pfree(edata->trigger_name);
+	if (edata->trigger_schema)
+		pfree(edata->trigger_schema);
 	pfree(edata);
 }
 
@@ -1449,6 +1595,24 @@ ReThrowError(ErrorData *edata)
 		newedata->context = pstrdup(newedata->context);
 	if (newedata->internalquery)
 		newedata->internalquery = pstrdup(newedata->internalquery);
+	if (newedata->column_name)
+		newedata->column_name = pstrdup(newedata->column_name);
+	if (newedata->table_name)
+		newedata->table_name = pstrdup(newedata->table_name);
+	if (newedata->schema_name)
+		newedata->schema_name = pstrdup(newedata->schema_name);
+	if (newedata->constraint_name)
+		newedata->constraint_name = pstrdup(newedata->constraint_name);
+	if (newedata->constraint_schema)
+		newedata->constraint_schema = pstrdup(newedata->constraint_schema);
+	if (newedata->routine_name)
+		newedata->routine_name = pstrdup(newedata->routine_name);
+	if (newedata->routine_schema)
+		newedata->routine_schema = pstrdup(newedata->routine_schema);
+	if (newedata->trigger_name)
+		newedata->trigger_name = pstrdup(newedata->trigger_name);
+	if (newedata->trigger_schema)
+		newedata->trigger_schema = pstrdup(newedata->trigger_schema);
 
 	recursion_depth--;
 	PG_RE_THROW();
@@ -2259,6 +2423,33 @@ write_csvlog(ErrorData *edata)
 	/* application name */
 	if (application_name)
 		appendCSVLiteral(&buf, application_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->column_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->table_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->schema_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->constraint_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->constraint_schema);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->routine_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->routine_schema);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->trigger_name);
+	appendStringInfoChar(&buf, ',');
+
+	appendCSVLiteral(&buf, edata->trigger_schema);
 
 	appendStringInfoChar(&buf, '\n');
 
@@ -2377,6 +2568,69 @@ send_message_to_server_log(ErrorData *edata)
 				appendStringInfo(&buf, _("LOCATION:  %s:%d\n"),
 								 edata->filename, edata->lineno);
 			}
+			if (edata->column_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("COLUMN NAME:  "));
+				append_with_tabs(&buf, edata->column_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->table_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("TABLE NAME:  "));
+				append_with_tabs(&buf, edata->table_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->schema_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("SCHEMA NAME:  "));
+				append_with_tabs(&buf, edata->schema_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->constraint_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("CONSTRAINT NAME:  "));
+				append_with_tabs(&buf, edata->constraint_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->constraint_schema)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("CONSTRAINT SCHEMA:  "));
+				append_with_tabs(&buf, edata->constraint_schema);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->routine_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("ROUTINE NAME:  "));
+				append_with_tabs(&buf, edata->routine_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->routine_schema)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("ROUTINE SCHEMA:  "));
+				append_with_tabs(&buf, edata->routine_schema);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->trigger_name)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("TRIGGER NAME:  "));
+				append_with_tabs(&buf, edata->trigger_name);
+				appendStringInfoChar(&buf, '\n');
+			}
+			if (edata->trigger_schema)
+			{
+				log_line_prefix(&buf, edata);
+				appendStringInfoString(&buf, _("TRIGGER SCHEMA:  "));
+				append_with_tabs(&buf, edata->trigger_schema);
+				appendStringInfoChar(&buf, '\n');
+			}
 		}
 	}
 
@@ -2673,6 +2927,60 @@ send_message_to_frontend(ErrorData *edata)
 			err_sendstring(&msgbuf, edata->funcname);
 		}
 
+		if (edata->column_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_COLUMN_NAME);
+			err_sendstring(&msgbuf, edata->column_name);
+		}
+
+		if (edata->table_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_TABLE_NAME);
+			err_sendstring(&msgbuf, edata->table_name);
+		}
+
+		if (edata->schema_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_SCHEMA_NAME);
+			err_sendstring(&msgbuf, edata->schema_name);
+		}
+
+		if (edata->constraint_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_CONSTRAINT_NAME);
+			err_sendstring(&msgbuf, edata->constraint_name);
+		}
+
+		if (edata->constraint_schema)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_CONSTRAINT_SCHEMA);
+			err_sendstring(&msgbuf, edata->constraint_schema);
+		}
+
+		if (edata->routine_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_ROUTINE_NAME);
+			err_sendstring(&msgbuf, edata->routine_name);
+		}
+
+		if (edata->routine_schema)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_ROUTINE_SCHEMA);
+			err_sendstring(&msgbuf, edata->routine_schema);
+		}
+
+		if (edata->trigger_name)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_TRIGGER_NAME);
+			err_sendstring(&msgbuf, edata->trigger_name);
+		}
+
+		if (edata->trigger_schema)
+		{
+			pq_sendbyte(&msgbuf, PG_DIAG_TRIGGER_SCHEMA);
+			err_sendstring(&msgbuf, edata->trigger_schema);
+		}
+
 		pq_sendbyte(&msgbuf, '\0');		/* terminator */
 	}
 	else
@@ -2977,3 +3285,19 @@ trace_recovery(int trace_level)
 
 	return trace_level;
 }
+
+/*
+ * Sets column_name, table_name and schema_name in ErrorData
+ */
+inline int
+schema_table_column_error(const char *schema_name, const char *table_name, const char *colname)
+{
+	if (colname != NULL)
+		erritem(PG_DIAG_COLUMN_NAME, colname);
+	if (table_name != NULL)
+		erritem(PG_DIAG_TABLE_NAME, table_name);
+	if (schema_name != NULL)
+		erritem(PG_DIAG_SCHEMA_NAME, schema_name);
+
+	return 0;					/* return value does not matter */
+}
diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h
index b6ebb7a..833c59e 100644
--- a/src/include/postgres_ext.h
+++ b/src/include/postgres_ext.h
@@ -55,5 +55,14 @@ typedef unsigned int Oid;
 #define PG_DIAG_SOURCE_FILE		'F'
 #define PG_DIAG_SOURCE_LINE		'L'
 #define PG_DIAG_SOURCE_FUNCTION 'R'
+#define PG_DIAG_COLUMN_NAME	'c'
+#define PG_DIAG_TABLE_NAME	't'
+#define PG_DIAG_SCHEMA_NAME	's'
+#define PG_DIAG_CONSTRAINT_NAME		'n'
+#define PG_DIAG_CONSTRAINT_SCHEMA	'm'
+#define PG_DIAG_ROUTINE_NAME		'r'
+#define PG_DIAG_ROUTINE_SCHEMA		'u'
+#define PG_DIAG_TRIGGER_NAME		'g'
+#define PG_DIAG_TRIGGER_SCHEMA		'h'
 
 #endif
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index 1bbfd2b..3ee120c 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -80,7 +80,6 @@
 #endif
 #endif
 
-
 /*----------
  * New-style error reporting API: to be used in this way:
  *		ereport(ERROR,
@@ -190,6 +189,8 @@ extern int	geterrcode(void);
 extern int	geterrposition(void);
 extern int	getinternalerrposition(void);
 
+extern int	erritem(int field, const char *str);
+
 
 /*----------
  * Old-style error reporting API: to be used in this way:
@@ -296,6 +297,7 @@ extern PGDLLIMPORT ErrorContextCallback *error_context_stack;
 extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
 
 
+
 /* Stuff that error handlers might want to use */
 
 /*
@@ -321,6 +323,15 @@ typedef struct ErrorData
 	char	   *detail_log;		/* detail error message for server log only */
 	char	   *hint;			/* hint message */
 	char	   *context;		/* context message */
+	char	   *column_name;		/* name of column */
+	char	   *table_name;			/* name of table */
+	char	   *schema_name;		/* name of schema */
+	char	   *constraint_name;		/* name of constraint */
+	char	   *constraint_schema;		/* name of schema with constraint */
+	char	   *routine_name;		/* name of function that caused error */
+	char	   *routine_schema;		/* schema name of function that caused error */
+	char	   *trigger_name;		/* name of trigger that caused error */
+	char	   *trigger_schema;		/* schema of trigger that caused error */
 	int			cursorpos;		/* cursor index into query string */
 	int			internalpos;	/* cursor index into internalquery */
 	char	   *internalquery;	/* text of internally-generated query */
@@ -378,4 +389,7 @@ write_stderr(const char *fmt,...)
    the supplied arguments. */
 __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 
+extern inline int schema_table_column_error(const char *schema_name, const char *table_name,
+									const char *colname);
+
 #endif   /* ELOG_H */
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index 696ca77..4bd17da 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -157,4 +157,6 @@ extern Oid get_range_subtype(Oid rangeOid);
 
 #define TypeIsToastable(typid)	(get_typstorage(typid) != 'p')
 
+extern inline int rel_column_error(Oid table_oid, const char *colname);
+
 #endif   /* LSYSCACHE_H */
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index d404c2a..9ea47d1 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -394,4 +394,11 @@ typedef struct StdRdOptions
 extern void RelationIncrementReferenceCount(Relation rel);
 extern void RelationDecrementReferenceCount(Relation rel);
 
+extern inline int relation_column_error(Relation rel, const char *colname);
+extern inline int relation_error(Relation rel);
+extern inline int constraint_error(Relation rel, const char *ccname);
+extern inline int constraint_relation_error(Relation rel);
+extern inline int column_error(const char *cname);
+
+
 #endif   /* REL_H */
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index a773d7a..b935a84 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -980,6 +980,34 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
 								  valf, vall);
 			appendPQExpBufferChar(&workBuf, '\n');
 		}
+
+		val = PQresultErrorField(res, PG_DIAG_COLUMN_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("COLUMN NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_TABLE_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("TABLE NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_SCHEMA_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("SCHEMA NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_CONSTRAINT_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("CONSTRAINT NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_CONSTRAINT_SCHEMA);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("CONSTRAINT SCHEMA:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_ROUTINE_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("ROUTINE NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_ROUTINE_SCHEMA);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("ROUTINE SCHEMA:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_TRIGGER_NAME);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("TRIGGER NAME:  %s\n"), val);
+		val = PQresultErrorField(res, PG_DIAG_TRIGGER_SCHEMA);
+		if (val)
+			appendPQExpBuffer(&workBuf, libpq_gettext("TRIGGER SCHEMA:  %s\n"), val);
 	}
 
 	/*
