Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde9801f

Browse files
committed
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
1 parentf736fdb commitde9801f

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

‎doc/src/sgml/func.sgml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.112 2002/08/16 23:01:18 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.113 2002/08/20 04:45:59 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -5082,6 +5082,11 @@ SELECT NULLIF(value, '(none)') ...
50825082
<entry><type>name[]</type></entry>
50835083
<entry>names of schemas in search path optionally including implicit schemas</entry>
50845084
</row>
5085+
<row>
5086+
<entry><function>current_database()</function></entry>
5087+
<entry><type>name</type></entry>
5088+
<entry>name of current database</entry>
5089+
</row>
50855090
</tbody>
50865091
</tgroup>
50875092
</table>

‎src/backend/utils/adt/misc.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.24 2002/06/2020:29:37 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.25 2002/08/2004:45:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -17,6 +17,7 @@
1717
#include<time.h>
1818

1919
#include"postgres.h"
20+
#include"miscadmin.h"
2021

2122
#include"utils/builtins.h"
2223

@@ -111,3 +112,19 @@ userfntest(PG_FUNCTION_ARGS)
111112

112113
PG_RETURN_INT32(i);
113114
}
115+
116+
/*
117+
* current_database()
118+
*Expose the current database to the user
119+
*/
120+
Datum
121+
current_database(PG_FUNCTION_ARGS)
122+
{
123+
Namedb;
124+
125+
db= (Name)palloc(NAMEDATALEN);
126+
127+
namestrcpy(db,DatabaseName);
128+
129+
PG_RETURN_NAME(db);
130+
}

‎src/include/catalog/pg_proc.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.256 2002/08/17 13:04:15 momjian Exp $
10+
* $Id: pg_proc.h,v 1.257 2002/08/2004:45:59 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1106,6 +1106,9 @@ DESCR("does not match LIKE expression");
11061106
DATA(insertOID=860 (bpcharPGNSPPGUID12fftfi11042"18"char_bpchar-_null_ ));
11071107
DESCR("convert char to char()");
11081108

1109+
DATA(insertOID=861 (current_databasePGNSPPGUID12fftfi019"0"current_database-_null_ ));
1110+
DESCR("returns the current database");
1111+
11091112
DATA(insertOID=862 (int4_mul_cashPGNSPPGUID12fftfi2790"23 790"int4_mul_cash-_null_ ));
11101113
DESCR("multiply");
11111114
DATA(insertOID=863 (int2_mul_cashPGNSPPGUID12fftfi2790"21 790"int2_mul_cash-_null_ ));

‎src/include/utils/builtins.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.192 2002/08/16 23:01:21 tgl Exp $
10+
* $Id: builtins.h,v 1.193 2002/08/20 04:46:00 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -315,6 +315,7 @@ extern Datum nonnullvalue(PG_FUNCTION_ARGS);
315315
externDatumoidrand(PG_FUNCTION_ARGS);
316316
externDatumoidsrand(PG_FUNCTION_ARGS);
317317
externDatumuserfntest(PG_FUNCTION_ARGS);
318+
externDatumcurrent_database(PG_FUNCTION_ARGS);
318319

319320
/* not_in.c */
320321
externDatumint4notin(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp