mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Add current_database().
> 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
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user