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

Commitf96928f

Browse files
committed
Implement current_query(), that shows the currently executing query.
At the same time remove dblink/dblink_current_query() as it is no longernecessary*BACKWARD COMPATIBILITY ISSUE* for dblinkTomas Doran
1 parentcfaf8b6 commitf96928f

File tree

11 files changed

+32
-87
lines changed

11 files changed

+32
-87
lines changed

‎contrib/dblink/dblink.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Darko Prenosil <Darko.Prenosil@finteh.hr>
99
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010
*
11-
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.71 2008/03/26 21:10:36 alvherre Exp $
11+
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.72 2008/04/04 16:57:21 momjian Exp $
1212
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
1313
* ALL RIGHTS RESERVED;
1414
*
@@ -1631,23 +1631,6 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
16311631
PG_RETURN_TEXT_P(cstring_to_text(sql));
16321632
}
16331633

1634-
/*
1635-
* dblink_current_query
1636-
* return the current query string
1637-
* to allow its use in (among other things)
1638-
* rewrite rules
1639-
*/
1640-
PG_FUNCTION_INFO_V1(dblink_current_query);
1641-
Datum
1642-
dblink_current_query(PG_FUNCTION_ARGS)
1643-
{
1644-
if (debug_query_string)
1645-
PG_RETURN_TEXT_P(cstring_to_text(debug_query_string));
1646-
else
1647-
PG_RETURN_NULL();
1648-
}
1649-
1650-
16511634
/*************************************************************
16521635
* internal functions
16531636
*/

‎contrib/dblink/dblink.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Darko Prenosil <Darko.Prenosil@finteh.hr>
99
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010
*
11-
* $PostgreSQL: pgsql/contrib/dblink/dblink.h,v 1.19 2008/01/01 19:45:45 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/dblink/dblink.h,v 1.20 2008/04/04 16:57:21 momjian Exp $
1212
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
1313
* ALL RIGHTS RESERVED;
1414
*
@@ -56,6 +56,5 @@ extern Datum dblink_get_pkey(PG_FUNCTION_ARGS);
5656
externDatumdblink_build_sql_insert(PG_FUNCTION_ARGS);
5757
externDatumdblink_build_sql_delete(PG_FUNCTION_ARGS);
5858
externDatumdblink_build_sql_update(PG_FUNCTION_ARGS);
59-
externDatumdblink_current_query(PG_FUNCTION_ARGS);
6059

6160
#endif/* DBLINK_H */

‎contrib/dblink/dblink.sql.in

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/dblink/dblink.sql.in,v 1.14 2007/11/13 04:24:27 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/dblink/dblink.sql.in,v 1.15 2008/04/04 16:57:21 momjian Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -163,11 +163,6 @@ RETURNS text
163163
AS 'MODULE_PATHNAME','dblink_build_sql_update'
164164
LANGUAGE C STRICT;
165165

166-
CREATE OR REPLACE FUNCTION dblink_current_query ()
167-
RETURNS text
168-
AS 'MODULE_PATHNAME','dblink_current_query'
169-
LANGUAGE C;
170-
171166
CREATE OR REPLACE FUNCTION dblink_send_query(text, text)
172167
RETURNS int4
173168
AS 'MODULE_PATHNAME', 'dblink_send_query'

‎contrib/dblink/expected/dblink.out

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ INSERT INTO foo VALUES (7,'h','{"a7","b7","c7"}');
2222
INSERT INTO foo VALUES (8,'i','{"a8","b8","c8"}');
2323
INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
2424
-- misc utilities
25-
-- show the currently executing query
26-
SELECT 'hello' AS hello, dblink_current_query() AS query;
27-
hello | query
28-
-------+-----------------------------------------------------------
29-
hello | SELECT 'hello' AS hello, dblink_current_query() AS query;
30-
(1 row)
31-
3225
-- list the primary key fields
3326
SELECT *
3427
FROM dblink_get_pkey('foo');

‎contrib/dblink/sql/dblink.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
2727

2828
-- misc utilities
2929

30-
-- show the currently executing query
31-
SELECT'hello'AS hello, dblink_current_query()AS query;
32-
3330
-- list the primary key fields
3431
SELECT*
3532
FROM dblink_get_pkey('foo');

‎contrib/dblink/uninstall_dblink.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/* $PostgreSQL: pgsql/contrib/dblink/uninstall_dblink.sql,v 1.5 2007/11/13 04:24:27 momjian Exp $*/
1+
/* $PostgreSQL: pgsql/contrib/dblink/uninstall_dblink.sql,v 1.6 2008/04/04 16:57:21 momjian Exp $*/
22

33
-- Adjust this setting to control where the objects get dropped.
44
SET search_path= public;
55

6-
DROPFUNCTION dblink_current_query ();
7-
86
DROPFUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text);
97

108
DROPFUNCTION dblink_build_sql_delete (text, int2vector, int4, _text);

‎doc/src/sgml/dblink.sgml

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/dblink.sgml,v 1.3 2007/12/06 04:12:09 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/dblink.sgml,v 1.4 2008/04/04 16:57:21 momjian Exp $ -->
22

33
<sect1 id="dblink">
44
<title>dblink</title>
@@ -1346,49 +1346,6 @@ SELECT *
13461346
</refsect1>
13471347
</refentry>
13481348

1349-
<refentry id="CONTRIB-DBLINK-CURRENT-QUERY">
1350-
<refnamediv>
1351-
<refname>dblink_current_query</refname>
1352-
<refpurpose>returns the current query string</refpurpose>
1353-
</refnamediv>
1354-
1355-
<refsynopsisdiv>
1356-
<synopsis>
1357-
dblink_current_query() returns text
1358-
</synopsis>
1359-
</refsynopsisdiv>
1360-
1361-
<refsect1>
1362-
<title>Description</title>
1363-
1364-
<para>
1365-
Returns the currently executing interactive command string of the
1366-
local database session, or NULL if it can't be determined. Note
1367-
that this function is not really related to <filename>dblink</>'s
1368-
other functionality. It is provided since it is sometimes useful
1369-
in generating queries to be forwarded to remote databases.
1370-
</para>
1371-
</refsect1>
1372-
1373-
<refsect1>
1374-
<title>Return Value</title>
1375-
1376-
<para>Returns a copy of the currently executing query string.</para>
1377-
</refsect1>
1378-
1379-
<refsect1>
1380-
<title>Example</title>
1381-
1382-
<programlisting>
1383-
test=# select dblink_current_query();
1384-
dblink_current_query
1385-
--------------------------------
1386-
select dblink_current_query();
1387-
(1 row)
1388-
</programlisting>
1389-
</refsect1>
1390-
</refentry>
1391-
13921349
<refentry id="CONTRIB-DBLINK-GET-PKEY">
13931350
<refnamediv>
13941351
<refname>dblink_get_pkey</refname>

‎doc/src/sgml/func.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.425 2008/03/23 00:24:19 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.426 2008/04/04 16:57:21 momjian Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -10724,6 +10724,12 @@ select current_date + s.a as dates from generate_series(0,14,7) as s(a);
1072410724
<entry>user name of current execution context</entry>
1072510725
</row>
1072610726

10727+
<row>
10728+
<entry><literal><function>current_query</function></literal></entry>
10729+
<entry><type>text</type></entry>
10730+
<entry>text of the currently executing query (might contain more than one statement)</entry>
10731+
</row>
10732+
1072710733
<row>
1072810734
<entry><literal><function>inet_client_addr</function>()</literal></entry>
1072910735
<entry><type>inet</type></entry>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.58 2008/01/01 19:45:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.59 2008/04/04 16:57:21 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,6 +29,7 @@
2929
#include"storage/pmsignal.h"
3030
#include"storage/procarray.h"
3131
#include"utils/builtins.h"
32+
#include"tcop/tcopprot.h"
3233

3334
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
3435

@@ -71,6 +72,19 @@ current_database(PG_FUNCTION_ARGS)
7172
}
7273

7374

75+
/*
76+
* current_query()
77+
* Expose the current query to the user (useful in stored procedures)
78+
*/
79+
Datum
80+
current_query(PG_FUNCTION_ARGS)
81+
{
82+
if (debug_query_string)
83+
PG_RETURN_TEXT_P(cstring_to_text(debug_query_string));
84+
else
85+
PG_RETURN_NULL();
86+
}
87+
7488
/*
7589
* Functions to send signals to other backends.
7690
*/

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.485 2008/03/27 03:57:34 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.486 2008/04/04 16:57:21 momjian Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1117,6 +1117,8 @@ DESCR("convert char to char()");
11171117

11181118
DATA(insertOID=861 (current_databasePGNSPPGUID1210fftfi019""_null__null__null_current_database-_null__null_ ));
11191119
DESCR("returns the current database");
1120+
DATA(insertOID=817 (current_queryPGNSPPGUID1210ffffv025""_null__null__null_current_query-_null__null_ ));
1121+
DESCR("returns the currently executing query");
11201122

11211123
DATA(insertOID=862 (int4_mul_cashPGNSPPGUID1210fftfi2790"23 790"_null__null__null_int4_mul_cash-_null__null_ ));
11221124
DESCR("multiply");

‎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-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.310 2008/03/25 22:42:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.311 2008/04/04 16:57:21 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -414,6 +414,7 @@ extern Datum pg_ls_dir(PG_FUNCTION_ARGS);
414414
externDatumnullvalue(PG_FUNCTION_ARGS);
415415
externDatumnonnullvalue(PG_FUNCTION_ARGS);
416416
externDatumcurrent_database(PG_FUNCTION_ARGS);
417+
externDatumcurrent_query(PG_FUNCTION_ARGS);
417418
externDatumpg_cancel_backend(PG_FUNCTION_ARGS);
418419
externDatumpg_reload_conf(PG_FUNCTION_ARGS);
419420
externDatumpg_tablespace_databases(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp