diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index bf2ce4667e2337a9af8507e10661a78fe397d02e..fddc65e84d3c2e0bb3baa5d558ffd54bf28df0b1 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.112 2002/08/16 23:01:18 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.113 2002/08/20 04:45:59 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -5082,6 +5082,11 @@ SELECT NULLIF(value, '(none)') ...
        <entry><type>name[]</type></entry>
        <entry>names of schemas in search path optionally including implicit schemas</entry>
       </row>
+      <row>
+       <entry><function>current_database()</function></entry>
+       <entry><type>name</type></entry>
+       <entry>name of current database</entry>
+      </row>
      </tbody>
     </tgroup>
    </table>
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 57640ef08d01828315ab82b02da10b8299fddf49..24eb68218437ceb4e490e9efdc8f58dd34415e3b 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.24 2002/06/20 20:29:37 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.25 2002/08/20 04:45:59 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,6 +17,7 @@
 #include <time.h>
 
 #include "postgres.h"
+#include "miscadmin.h"
 
 #include "utils/builtins.h"
 
@@ -111,3 +112,19 @@ userfntest(PG_FUNCTION_ARGS)
 
 	PG_RETURN_INT32(i);
 }
+
+/*
+ * current_database()
+ *	Expose the current database to the user
+ */
+Datum
+current_database(PG_FUNCTION_ARGS)
+{
+	Name   db;
+
+	db = (Name) palloc(NAMEDATALEN);
+
+	namestrcpy(db, DatabaseName);
+
+	PG_RETURN_NAME(db);
+}
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 2213fe7228c146579630bfd651129fc759c5ce6b..a186cb0825603be77b6cd0a06d8e147feec675bf 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_proc.h,v 1.256 2002/08/17 13:04:15 momjian Exp $
+ * $Id: pg_proc.h,v 1.257 2002/08/20 04:45:59 momjian Exp $
  *
  * NOTES
  *	  The script catalog/genbki.sh reads this file and generates .bki
@@ -1106,6 +1106,9 @@ DESCR("does not match LIKE expression");
 DATA(insert OID =  860 (  bpchar		   PGNSP PGUID 12 f f t f i 1 1042 "18"  char_bpchar - _null_ ));
 DESCR("convert char to char()");
 
+DATA(insert OID = 861 ( current_database       PGNSP PGUID 12 f f t f i 0 19 "0" current_database - _null_ ));
+DESCR("returns the current database");
+
 DATA(insert OID =  862 (  int4_mul_cash		   PGNSP PGUID 12 f f t f i 2 790 "23 790"  int4_mul_cash - _null_ ));
 DESCR("multiply");
 DATA(insert OID =  863 (  int2_mul_cash		   PGNSP PGUID 12 f f t f i 2 790 "21 790"  int2_mul_cash - _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 3588673c2aec2cea41d813c1f9a6aada51ceb7db..e9937ad751e2809aa03c814ddc945b1160bd312f 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: builtins.h,v 1.192 2002/08/16 23:01:21 tgl Exp $
+ * $Id: builtins.h,v 1.193 2002/08/20 04:46:00 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -315,6 +315,7 @@ extern Datum nonnullvalue(PG_FUNCTION_ARGS);
 extern Datum oidrand(PG_FUNCTION_ARGS);
 extern Datum oidsrand(PG_FUNCTION_ARGS);
 extern Datum userfntest(PG_FUNCTION_ARGS);
+extern Datum current_database(PG_FUNCTION_ARGS);
 
 /* not_in.c */
 extern Datum int4notin(PG_FUNCTION_ARGS);