> Quick system function to pull out the current database.
>
> I've used this a number of times to allow stored procedures to find out
> where they are. Especially useful for those that do logging or hit a
> remote server.
>
> It's called current_database() to match with current_user().
It's also a necessity for an informational schema. The catalog
(database) name is required in a number of places.
Rod Taylor
name[]
names of schemas in search path optionally including implicit schemas
+ |
+ current_database()
+ name
+ name of current database
+
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include
#include "postgres.h"
+#include "miscadmin.h"
#include "utils/builtins.h"
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);
+}
* 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
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_ ));
* 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 $
*
*-------------------------------------------------------------------------
*/
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);