diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 15d6a1bb68d65838ab2a15d0de9a6239500e94a2..2f0e7dc7ea4c7112b095fdae562f4da73c99baff 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.120 2003/08/26 21:15:27 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.121 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1165,7 +1165,7 @@ send_message_to_frontend(ErrorData *edata)
 		int			ssval;
 		int			i;
 
-		pq_sendbyte(&msgbuf, 'S');
+		pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY);
 		pq_sendstring(&msgbuf, error_severity(edata->elevel));
 
 		/* unpack MAKE_SQLSTATE code */
@@ -1177,11 +1177,11 @@ send_message_to_frontend(ErrorData *edata)
 		}
 		tbuf[i] = '\0';
 
-		pq_sendbyte(&msgbuf, 'C');
+		pq_sendbyte(&msgbuf, PG_DIAG_SQLSTATE);
 		pq_sendstring(&msgbuf, tbuf);
 
 		/* M field is required per protocol, so always send something */
-		pq_sendbyte(&msgbuf, 'M');
+		pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_PRIMARY);
 		if (edata->message)
 			pq_sendstring(&msgbuf, edata->message);
 		else
@@ -1189,45 +1189,45 @@ send_message_to_frontend(ErrorData *edata)
 
 		if (edata->detail)
 		{
-			pq_sendbyte(&msgbuf, 'D');
+			pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_DETAIL);
 			pq_sendstring(&msgbuf, edata->detail);
 		}
 
 		if (edata->hint)
 		{
-			pq_sendbyte(&msgbuf, 'H');
+			pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_HINT);
 			pq_sendstring(&msgbuf, edata->hint);
 		}
 
 		if (edata->context)
 		{
-			pq_sendbyte(&msgbuf, 'W');
+			pq_sendbyte(&msgbuf, PG_DIAG_CONTEXT);
 			pq_sendstring(&msgbuf, edata->context);
 		}
 
 		if (edata->cursorpos > 0)
 		{
 			snprintf(tbuf, sizeof(tbuf), "%d", edata->cursorpos);
-			pq_sendbyte(&msgbuf, 'P');
+			pq_sendbyte(&msgbuf, PG_DIAG_STATEMENT_POSITION);
 			pq_sendstring(&msgbuf, tbuf);
 		}
 
 		if (edata->filename)
 		{
-			pq_sendbyte(&msgbuf, 'F');
+			pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_FILE);
 			pq_sendstring(&msgbuf, edata->filename);
 		}
 
 		if (edata->lineno > 0)
 		{
 			snprintf(tbuf, sizeof(tbuf), "%d", edata->lineno);
-			pq_sendbyte(&msgbuf, 'L');
+			pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_LINE);
 			pq_sendstring(&msgbuf, tbuf);
 		}
 
 		if (edata->funcname)
 		{
-			pq_sendbyte(&msgbuf, 'R');
+			pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_FUNCTION);
 			pq_sendstring(&msgbuf, edata->funcname);
 		}
 
diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h
index b252453bbff4cc35f695e10f16e8a33f00dcb96d..c61bd4de0fe06df43b115cb3ca5e75f64aace8ba 100644
--- a/src/include/postgres_ext.h
+++ b/src/include/postgres_ext.h
@@ -15,7 +15,7 @@
  *	use header files that are otherwise internal to Postgres to interface
  *	with the backend.
  *
- * $Id: postgres_ext.h,v 1.12 2003/03/18 17:21:07 momjian Exp $
+ * $Id: postgres_ext.h,v 1.13 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -47,4 +47,21 @@ typedef unsigned int Oid;
  */
 #define NAMEDATALEN 64
 
+
+/*
+ * Identifiers of error message fields.  Kept here to keep common
+ * between frontend and backend, and also to export them to libpq
+ * applications.
+ */
+#define PG_DIAG_SEVERITY		'S'
+#define PG_DIAG_SQLSTATE		'C'
+#define PG_DIAG_MESSAGE_PRIMARY	'M'
+#define PG_DIAG_MESSAGE_DETAIL	'D'
+#define PG_DIAG_MESSAGE_HINT	'H'
+#define PG_DIAG_STATEMENT_POSITION 'P'
+#define PG_DIAG_CONTEXT			'W'
+#define PG_DIAG_SOURCE_FILE		'F'
+#define PG_DIAG_SOURCE_LINE		'L'
+#define PG_DIAG_SOURCE_FUNCTION	'R'
+
 #endif
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 3e6527668137d47d4352b898066450ccf802154c..f9ce9564a7cdf0fc969014685710ea6425022ac0 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.145 2003/08/13 18:56:21 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.146 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -480,8 +480,8 @@ pqInternalNotice(const PGNoticeHooks * hooks, const char *fmt,...)
 	/*
 	 * Set up fields of notice.
 	 */
-	pqSaveMessageField(res, 'M', msgBuf);
-	pqSaveMessageField(res, 'S', libpq_gettext("NOTICE"));
+	pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, msgBuf);
+	pqSaveMessageField(res, PG_DIAG_SEVERITY, libpq_gettext("NOTICE"));
 	/* XXX should provide a SQLSTATE too? */
 
 	/*
diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c
index 834aa69bbf4b27def48e7c798f470452638da5bc..1b766996910ed6fb3e57fd2a4a33bb478ad3f273 100644
--- a/src/interfaces/libpq/fe-protocol2.c
+++ b/src/interfaces/libpq/fe-protocol2.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.6 2003/08/04 02:40:20 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.7 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -828,7 +828,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
 	{
 		/* what comes before the colon is severity */
 		*splitp = '\0';
-		pqSaveMessageField(res, 'S', workBuf.data);
+		pqSaveMessageField(res, PG_DIAG_SEVERITY, workBuf.data);
 		startp = splitp + 3;
 	}
 	else
@@ -841,16 +841,16 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
 	{
 		/* what comes before the newline is primary message */
 		*splitp++ = '\0';
-		pqSaveMessageField(res, 'M', startp);
+		pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, startp);
 		/* the rest is detail; strip any leading whitespace */
 		while (*splitp && isspace((unsigned char) *splitp))
 			splitp++;
-		pqSaveMessageField(res, 'D', splitp);
+		pqSaveMessageField(res, PG_DIAG_MESSAGE_DETAIL, splitp);
 	}
 	else
 	{
 		/* single-line message, so all primary */
-		pqSaveMessageField(res, 'M', startp);
+		pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, startp);
 	}
 
 	/*
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 0591d63da98fed4c1f268b3b833fb1d30e13a7c9..ba06a37848f8893e9d605a064e4db43f2739ce62 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.8 2003/08/13 18:56:21 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.9 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -614,19 +614,19 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
 	 * Now build the "overall" error message for PQresultErrorMessage.
 	 */
 	resetPQExpBuffer(&workBuf);
-	val = PQresultErrorField(res, 'S'); /* Severity */
+	val = PQresultErrorField(res, PG_DIAG_SEVERITY);
 	if (val)
 		appendPQExpBuffer(&workBuf, "%s:  ", val);
 	if (conn->verbosity == PQERRORS_VERBOSE)
 	{
-		val = PQresultErrorField(res, 'C');		/* SQLSTATE Code */
+		val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
 		if (val)
 			appendPQExpBuffer(&workBuf, "%s: ", val);
 	}
-	val = PQresultErrorField(res, 'M'); /* Primary message */
+	val = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
 	if (val)
 		appendPQExpBufferStr(&workBuf, val);
-	val = PQresultErrorField(res, 'P'); /* Position */
+	val = PQresultErrorField(res, PG_DIAG_STATEMENT_POSITION);
 	if (val)
 	{
 		/* translator: %s represents a digit string */
@@ -635,13 +635,13 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
 	appendPQExpBufferChar(&workBuf, '\n');
 	if (conn->verbosity != PQERRORS_TERSE)
 	{
-		val = PQresultErrorField(res, 'D');		/* Detail */
+		val = PQresultErrorField(res, PG_DIAG_MESSAGE_DETAIL);
 		if (val)
 			appendPQExpBuffer(&workBuf, libpq_gettext("DETAIL:  %s\n"), val);
-		val = PQresultErrorField(res, 'H');		/* Hint */
+		val = PQresultErrorField(res, PG_DIAG_MESSAGE_HINT);
 		if (val)
 			appendPQExpBuffer(&workBuf, libpq_gettext("HINT:  %s\n"), val);
-		val = PQresultErrorField(res, 'W');		/* Where */
+		val = PQresultErrorField(res, PG_DIAG_CONTEXT);
 		if (val)
 			appendPQExpBuffer(&workBuf, libpq_gettext("CONTEXT:  %s\n"), val);
 	}
@@ -650,9 +650,9 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
 		const char *valf;
 		const char *vall;
 
-		valf = PQresultErrorField(res, 'F');	/* File */
-		vall = PQresultErrorField(res, 'L');	/* Line */
-		val = PQresultErrorField(res, 'R');		/* Routine */
+		valf = PQresultErrorField(res, PG_DIAG_SOURCE_FILE);
+		vall = PQresultErrorField(res, PG_DIAG_SOURCE_LINE);
+		val = PQresultErrorField(res, PG_DIAG_SOURCE_FUNCTION);
 		if (val || valf || vall)
 		{
 			appendPQExpBufferStr(&workBuf, libpq_gettext("LOCATION:  "));
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index 3e068cc6dc942f53f1435e9ed920ae756a5ec7fc..bafe0ddd6c94a8d3931d422ae0b6f680f79d0bdc 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-fe.h,v 1.99 2003/08/24 18:36:38 petere Exp $
+ * $Id: libpq-fe.h,v 1.100 2003/08/27 00:33:34 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -104,18 +104,6 @@ typedef enum
 	PQERRORS_VERBOSE			/* all the facts, ma'am */
 } PGVerbosity;
 
-/* for PQresultErrorField() */
-#define PG_DIAG_SEVERITY		'S'
-#define PG_DIAG_SQLSTATE		'C'
-#define PG_DIAG_MESSAGE_PRIMARY	'M'
-#define PG_DIAG_MESSAGE_DETAIL	'D'
-#define PG_DIAG_MESSAGE_HINT	'H'
-#define PG_DIAG_STATEMENT_POSITION 'P'
-#define PG_DIAG_CONTEXT			'W'
-#define PG_DIAG_SOURCE_FILE		'F'
-#define PG_DIAG_SOURCE_LINE		'L'
-#define PG_DIAG_SOURCE_FUNCTION	'R'
-
 /* PGconn encapsulates a connection to the backend.
  * The contents of this struct are not supposed to be known to applications.
  */