diff -Naur pgsql.virg/src/backend/utils/adt/acl.c pgsql.dev/src/backend/utils/adt/acl.c
--- pgsql.virg/src/backend/utils/adt/acl.c	Sun Jun  3 02:29:13 2001
+++ pgsql.dev/src/backend/utils/adt/acl.c	Sun Jun  3 02:23:17 2001
@@ -756,3 +756,366 @@
 	pfree(str.data);
 	return n;
 }
+
+
+/*
+ * has_table_privilege_name_name
+ *		Check user privileges on a relation given
+ *		usename, relname, and priv name.
+ *		If usename is omitted, current_user is assumed
+ *
+ * RETURNS
+ *		a boolean value
+ *		't' indicating user has the privilege
+ *		'f' indicating user does not have the privilege
+ */
+Datum
+has_table_privilege_name_name(PG_FUNCTION_ARGS)
+{
+	text		*username_text = NULL;
+	char		*username = NULL;
+	Oid			usesysid = (Oid) -1;
+	text		*relname_text = NULL;
+	char		*relname = NULL;
+	text		*priv_type_text = NULL;
+	HeapTuple	tuple;
+	AclMode		mode;
+	int32		result;
+
+	if (PG_NARGS == 2) {
+
+		relname_text = PG_GETARG_TEXT_P(0);
+		priv_type_text = PG_GETARG_TEXT_P(1);
+
+		usesysid = GetUserId();
+
+	} else if (PG_NARGS == 3) {
+
+		username_text = PG_GETARG_TEXT_P(0);
+		relname_text = PG_GETARG_TEXT_P(1);
+		priv_type_text = PG_GETARG_TEXT_P(2);
+
+		/* 
+		 * Convert username 'text' pattern to null-terminated string
+		 */
+		username = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(username_text)));
+
+		/*
+		 * Lookup userid based on username
+		 */
+
+		tuple = SearchSysCache(SHADOWNAME, NameGetDatum(username), 0, 0, 0);
+		if (!HeapTupleIsValid(tuple)) {
+			elog(ERROR, "has_table_privilege: invalid user name %s", (char *) username);
+		}
+
+		usesysid = (Oid) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
+
+		ReleaseSysCache(tuple);
+
+	} else {
+		/* 
+		 * should never get here!
+		 */
+
+		elog(ERROR, "has_table_privilege: wrong number of arguments %d", PG_NARGS);
+
+	}
+
+	/* 
+	 * Convert relname 'text' pattern to null-terminated string
+	 */
+	relname = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(relname_text)));
+
+	/*
+	 * Check relname is valid.
+	 * This is needed to deal with the case when usename is a superuser
+	 * in which case pg_aclcheck simply returns ACLCHECK_OK
+	 * without validating relname
+	 */
+	tuple = SearchSysCache(RELNAME, PointerGetDatum(relname), 0, 0, 0);
+
+	if (!HeapTupleIsValid(tuple)) {
+		elog(ERROR, "has_table_privilege: invalid relname %s", relname);
+	}
+	ReleaseSysCache(tuple);
+
+	/* 
+	 * Convert priv_type_text to an AclMode
+	 */
+	mode = convert_priv_string(priv_type_text);
+
+	/* 
+	 * Finally, check for the privilege
+	 */
+	result = pg_aclcheck(relname, usesysid, mode);
+
+	if (result == ACLCHECK_OK) {
+		PG_RETURN_BOOL(TRUE);
+	} else {
+		PG_RETURN_BOOL(FALSE);
+	}
+
+}
+
+
+/*
+ * has_table_privilege_name_id
+ *		Check user privileges on a relation given
+ *		usename, rel oid, and priv name.
+ *		If usename is omitted, current_user is assumed
+ *
+ * RETURNS
+ *		a boolean value
+ *		't' indicating user has the privilege
+ *		'f' indicating user does not have the privilege
+ */
+Datum
+has_table_privilege_name_id(PG_FUNCTION_ARGS)
+{
+	text		*username_text = NULL;
+	char		*username = NULL;
+	Oid			usesysid = (Oid) -1;
+	Oid			reloid = 0;
+	char		*relname = NULL;
+	text		*priv_type_text = NULL;
+	HeapTuple	tuple;
+	AclMode		mode;
+	int32		result;
+
+	if (PG_NARGS == 2) {
+
+		reloid = PG_GETARG_OID(0);
+		priv_type_text = PG_GETARG_TEXT_P(1);
+
+		usesysid = GetUserId();
+
+	} else if (PG_NARGS == 3) {
+
+		username_text = PG_GETARG_TEXT_P(0);
+		reloid = PG_GETARG_OID(1);
+		priv_type_text = PG_GETARG_TEXT_P(2);
+
+		/* 
+		 * Convert username 'text' pattern to null-terminated string
+		 */
+		username = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(username_text)));
+
+		/*
+		 * Lookup userid based on username
+		 */
+
+		tuple = SearchSysCache(SHADOWNAME, NameGetDatum(username), 0, 0, 0);
+		if (!HeapTupleIsValid(tuple)) {
+			elog(ERROR, "has_table_privilege: invalid user name %s", (char *) username);
+		}
+
+		usesysid = (Oid) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
+
+		ReleaseSysCache(tuple);
+
+	} else {
+		/* 
+		 * should never get here!
+		 */
+
+		elog(ERROR, "has_table_privilege: wrong number of arguments %d", PG_NARGS);
+
+	}
+
+	/*
+	 * Lookup relname based on rel oid
+	 */
+	tuple = SearchSysCache(RELOID, ObjectIdGetDatum(reloid), 0, 0, 0);
+	if (!HeapTupleIsValid(tuple)) {
+		elog(ERROR, "has_table_privilege: invalid relation oid %d", (int) reloid);
+	}
+
+	relname = NameStr(((Form_pg_class) GETSTRUCT(tuple))->relname);
+
+	ReleaseSysCache(tuple);
+
+	/* 
+	 * Convert priv_type_text to an AclMode
+	 */
+	mode = convert_priv_string(priv_type_text);
+
+	/* 
+	 * Finally, check for the privilege
+	 */
+	result = pg_aclcheck(relname, usesysid, mode);
+
+	if (result == ACLCHECK_OK) {
+		PG_RETURN_BOOL(TRUE);
+	} else {
+		PG_RETURN_BOOL(FALSE);
+	}
+
+}
+
+
+/*
+ * has_table_privilege_id_name
+ *		Check user privileges on a relation given
+ *		usesysid, relname, and priv name.
+ *
+ * RETURNS
+ *		a boolean value
+ *		't' indicating user has the privilege
+ *		'f' indicating user does not have the privilege
+ */
+Datum
+has_table_privilege_id_name(PG_FUNCTION_ARGS)
+{
+	Oid			usesysid;
+	text		*relname_text;
+	char		*relname;
+	text		*priv_type_text;
+	HeapTuple	tuple;
+	AclMode		mode;
+	int32		result;
+
+	usesysid = PG_GETARG_OID(0);
+	relname_text = PG_GETARG_TEXT_P(1);
+	priv_type_text = PG_GETARG_TEXT_P(2);
+
+	/* 
+	 * Convert relname 'text' pattern to null-terminated string
+	 */
+	relname = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(relname_text)));
+
+	/*
+	 * Check relname is valid.
+	 * This is needed to deal with the case when usename is a superuser
+	 * in which case pg_aclcheck simply returns ACLCHECK_OK
+	 * without validating relname
+	 */
+	tuple = SearchSysCache(RELNAME, PointerGetDatum(relname), 0, 0, 0);
+
+	if (!HeapTupleIsValid(tuple)) {
+		elog(ERROR, "has_table_privilege: invalid relname %s", relname);
+	}
+	ReleaseSysCache(tuple);
+
+	/* 
+	 * Convert priv_type_text to an AclMode
+	 */
+	mode = convert_priv_string(priv_type_text);
+
+	/* 
+	 * Finally, check for the privilege
+	 */
+	result = pg_aclcheck(relname, usesysid, mode);
+
+	if (result == ACLCHECK_OK) {
+		PG_RETURN_BOOL(TRUE);
+	} else {
+		PG_RETURN_BOOL(FALSE);
+	}
+
+}
+
+
+/*
+ * has_table_privilege_id_id
+ *		Check user privileges on a relation given
+ *		usesysid, rel oid, and priv name.
+ *
+ * RETURNS
+ *		a boolean value
+ *		't' indicating user has the privilege
+ *		'f' indicating user does not have the privilege
+ */
+Datum
+has_table_privilege_id_id(PG_FUNCTION_ARGS)
+{
+	Oid			usesysid;
+	Oid			reloid;
+	char		*relname;
+	text		*priv_type_text;
+	HeapTuple	tuple;
+	AclMode		mode;
+	int32		result;
+
+
+	usesysid = PG_GETARG_OID(0);
+	reloid = PG_GETARG_OID(1);
+	priv_type_text = PG_GETARG_TEXT_P(2);
+
+	/*
+	 * Lookup relname based on rel oid
+	 */
+	tuple = SearchSysCache(RELOID, ObjectIdGetDatum(reloid), 0, 0, 0);
+	if (!HeapTupleIsValid(tuple)) {
+		elog(ERROR, "has_table_privilege: invalid relation oid %d", (int) reloid);
+	}
+
+	relname = NameStr(((Form_pg_class) GETSTRUCT(tuple))->relname);
+
+	ReleaseSysCache(tuple);
+
+	/* 
+	 * Convert priv_type_text to an AclMode
+	 */
+	mode = convert_priv_string(priv_type_text);
+
+	/* 
+	 * Finally, check for the privilege
+	 */
+	result = pg_aclcheck(relname, usesysid, mode);
+
+	if (result == ACLCHECK_OK) {
+		PG_RETURN_BOOL(TRUE);
+	} else {
+		PG_RETURN_BOOL(FALSE);
+	}
+
+}
+
+/*
+ * convert_priv_string
+ *		Internal function.
+ *		Return mode from priv_type string
+ *
+ * RETURNS
+ *		AclMode
+ */
+
+AclMode
+convert_priv_string(text *priv_type_text)
+{
+	char	*priv_type = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(priv_type_text)));
+
+	/*
+	 * Return mode from priv_type string
+	 */
+	if (strcasecmp(priv_type, "SELECT") == 0)
+		return ACL_SELECT;
+
+	if (strcasecmp(priv_type, "INSERT") == 0)
+		return ACL_INSERT;
+
+	if (strcasecmp(priv_type, "UPDATE") == 0)
+		return ACL_UPDATE;
+
+	if (strcasecmp(priv_type, "DELETE") == 0)
+		return ACL_DELETE;
+
+	if (strcasecmp(priv_type, "RULE") == 0)
+		return ACL_RULE;
+
+	if (strcasecmp(priv_type, "REFERENCES") == 0)
+		return ACL_REFERENCES;
+
+	if (strcasecmp(priv_type, "TRIGGER") == 0)
+		return ACL_TRIGGER;
+
+	elog(ERROR, "has_table_privilege: invalid privilege type %s", priv_type);
+	/*
+	 * We should never get here, but stop the compiler from complaining
+	 */
+	return ACL_NO;
+
+}
+
+
diff -Naur pgsql.virg/src/include/catalog/pg_proc.h pgsql.dev/src/include/catalog/pg_proc.h
--- pgsql.virg/src/include/catalog/pg_proc.h	Sun Jun  3 02:29:15 2001
+++ pgsql.dev/src/include/catalog/pg_proc.h	Sun Jun  3 00:52:19 2001
@@ -2614,6 +2614,20 @@
 DATA(insert OID = 1909 (  int8shr		   PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100	int8shr - ));
 DESCR("binary shift right");
 
+DATA(insert OID = 1920 (  has_table_privilege		   PGUID 12 f t f t 3 f 16 "25 25 25" 100 0 0 100	has_table_privilege_name_name - ));
+DESCR("user privilege on relation by username, relname");
+DATA(insert OID = 1921 (  has_table_privilege		   PGUID 12 f t f t 3 f 16 "25 26 25" 100 0 0 100	has_table_privilege_name_id - ));
+DESCR("user privilege on relation by username, rel oid");
+DATA(insert OID = 1922 (  has_table_privilege		   PGUID 12 f t f t 3 f 16 "26 25 25" 100 0 0 100	has_table_privilege_id_name - ));
+DESCR("user privilege on relation by usesysid, relname");
+DATA(insert OID = 1923 (  has_table_privilege		   PGUID 12 f t f t 3 f 16 "26 26 25" 100 0 0 100	has_table_privilege_id_id - ));
+DESCR("user privilege on relation by usesysid, rel oid");
+DATA(insert OID = 1924 (  has_table_privilege		   PGUID 12 f t f t 2 f 16 "25 25" 100 0 0 100	has_table_privilege_name_name - ));
+DESCR("current user privilege on relation by relname");
+DATA(insert OID = 1925 (  has_table_privilege		   PGUID 12 f t f t 2 f 16 "26 25" 100 0 0 100	has_table_privilege_name_id - ));
+DESCR("current user privilege on relation by rel oid");
+
+
 /*
  * prototypes for functions pg_proc.c
  */
diff -Naur pgsql.virg/src/include/fmgr.h pgsql.dev/src/include/fmgr.h
--- pgsql.virg/src/include/fmgr.h	Sun Jun  3 02:29:17 2001
+++ pgsql.dev/src/include/fmgr.h	Sat Jun  2 23:56:01 2001
@@ -144,6 +144,7 @@
 
 /* Macros for fetching arguments of standard types */
 
+#define PG_NARGS             (fcinfo->nargs)
 #define PG_GETARG_DATUM(n)	 (fcinfo->arg[n])
 #define PG_GETARG_INT32(n)	 DatumGetInt32(PG_GETARG_DATUM(n))
 #define PG_GETARG_UINT32(n)  DatumGetUInt32(PG_GETARG_DATUM(n))
diff -Naur pgsql.virg/src/include/utils/acl.h pgsql.dev/src/include/utils/acl.h
--- pgsql.virg/src/include/utils/acl.h	Sun Jun  3 02:29:17 2001
+++ pgsql.dev/src/include/utils/acl.h	Sun Jun  3 00:37:19 2001
@@ -164,6 +164,7 @@
 #define ACLCHECK_NO_CLASS		  2
 #define ACLCHECK_NOT_OWNER		  3
 
+
 /* warning messages.  set these in aclchk.c. */
 extern char *aclcheck_error_strings[];
 
@@ -174,6 +175,8 @@
 
 extern Acl *aclinsert3(Acl *old_acl, AclItem *mod_aip, unsigned modechg);
 
+extern AclMode convert_priv_string(text *priv_type_text);
+
 /*
  * routines used by the parser
  */
@@ -192,6 +195,11 @@
 extern Datum aclremove(PG_FUNCTION_ARGS);
 extern Datum aclcontains(PG_FUNCTION_ARGS);
 extern void ExecuteChangeACLStmt(ChangeACLStmt *stmt);
+
+extern Datum has_table_privilege_name_name(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_name_id(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_id_name(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_id_id(PG_FUNCTION_ARGS);
 
 /*
  * prototypes for functions in aclchk.c
diff -Naur pgsql.virg/src/include/utils/builtins.h pgsql.dev/src/include/utils/builtins.h
--- pgsql.virg/src/include/utils/builtins.h	Sun Jun  3 02:29:19 2001
+++ pgsql.dev/src/include/utils/builtins.h	Sat Jun  2 23:59:45 2001
@@ -22,6 +22,13 @@
 /*
  *		Defined in adt/
  */
+
+/* acl.c */
+extern Datum has_table_privilege_name_name(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_name_id(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_id_name(PG_FUNCTION_ARGS);
+extern Datum has_table_privilege_id_id(PG_FUNCTION_ARGS);
+
 /* bool.c */
 extern Datum boolin(PG_FUNCTION_ARGS);
 extern Datum boolout(PG_FUNCTION_ARGS);
