mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-18 18:44:06 +08: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:
parent
f736fdb022
commit
de9801fc62
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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_ ));
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user