mirror of
https://github.com/postgres/postgres.git
synced 2025-05-14 00:03:46 -04:00
Implement current_query(), that shows the currently executing query.
At the same time remove dblink/dblink_current_query() as it is no longer necessary *BACKWARD COMPATIBILITY ISSUE* for dblink Tomas Doran
This commit is contained in:
parent
cfaf8b6b67
commit
f96928fde9
@ -8,7 +8,7 @@
|
|||||||
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
||||||
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.71 2008/03/26 21:10:36 alvherre Exp $
|
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.72 2008/04/04 16:57:21 momjian Exp $
|
||||||
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
||||||
* ALL RIGHTS RESERVED;
|
* ALL RIGHTS RESERVED;
|
||||||
*
|
*
|
||||||
@ -1631,23 +1631,6 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_TEXT_P(cstring_to_text(sql));
|
PG_RETURN_TEXT_P(cstring_to_text(sql));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* dblink_current_query
|
|
||||||
* return the current query string
|
|
||||||
* to allow its use in (among other things)
|
|
||||||
* rewrite rules
|
|
||||||
*/
|
|
||||||
PG_FUNCTION_INFO_V1(dblink_current_query);
|
|
||||||
Datum
|
|
||||||
dblink_current_query(PG_FUNCTION_ARGS)
|
|
||||||
{
|
|
||||||
if (debug_query_string)
|
|
||||||
PG_RETURN_TEXT_P(cstring_to_text(debug_query_string));
|
|
||||||
else
|
|
||||||
PG_RETURN_NULL();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* internal functions
|
* internal functions
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
||||||
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/contrib/dblink/dblink.h,v 1.19 2008/01/01 19:45:45 momjian Exp $
|
* $PostgreSQL: pgsql/contrib/dblink/dblink.h,v 1.20 2008/04/04 16:57:21 momjian Exp $
|
||||||
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
||||||
* ALL RIGHTS RESERVED;
|
* ALL RIGHTS RESERVED;
|
||||||
*
|
*
|
||||||
@ -56,6 +56,5 @@ extern Datum dblink_get_pkey(PG_FUNCTION_ARGS);
|
|||||||
extern Datum dblink_build_sql_insert(PG_FUNCTION_ARGS);
|
extern Datum dblink_build_sql_insert(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS);
|
extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS);
|
extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_current_query(PG_FUNCTION_ARGS);
|
|
||||||
|
|
||||||
#endif /* DBLINK_H */
|
#endif /* DBLINK_H */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/contrib/dblink/dblink.sql.in,v 1.14 2007/11/13 04:24:27 momjian Exp $ */
|
/* $PostgreSQL: pgsql/contrib/dblink/dblink.sql.in,v 1.15 2008/04/04 16:57:21 momjian Exp $ */
|
||||||
|
|
||||||
-- Adjust this setting to control where the objects get created.
|
-- Adjust this setting to control where the objects get created.
|
||||||
SET search_path = public;
|
SET search_path = public;
|
||||||
@ -163,11 +163,6 @@ RETURNS text
|
|||||||
AS 'MODULE_PATHNAME','dblink_build_sql_update'
|
AS 'MODULE_PATHNAME','dblink_build_sql_update'
|
||||||
LANGUAGE C STRICT;
|
LANGUAGE C STRICT;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION dblink_current_query ()
|
|
||||||
RETURNS text
|
|
||||||
AS 'MODULE_PATHNAME','dblink_current_query'
|
|
||||||
LANGUAGE C;
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION dblink_send_query(text, text)
|
CREATE OR REPLACE FUNCTION dblink_send_query(text, text)
|
||||||
RETURNS int4
|
RETURNS int4
|
||||||
AS 'MODULE_PATHNAME', 'dblink_send_query'
|
AS 'MODULE_PATHNAME', 'dblink_send_query'
|
||||||
|
@ -22,13 +22,6 @@ INSERT INTO foo VALUES (7,'h','{"a7","b7","c7"}');
|
|||||||
INSERT INTO foo VALUES (8,'i','{"a8","b8","c8"}');
|
INSERT INTO foo VALUES (8,'i','{"a8","b8","c8"}');
|
||||||
INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
|
INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
|
||||||
-- misc utilities
|
-- misc utilities
|
||||||
-- show the currently executing query
|
|
||||||
SELECT 'hello' AS hello, dblink_current_query() AS query;
|
|
||||||
hello | query
|
|
||||||
-------+-----------------------------------------------------------
|
|
||||||
hello | SELECT 'hello' AS hello, dblink_current_query() AS query;
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
-- list the primary key fields
|
-- list the primary key fields
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink_get_pkey('foo');
|
FROM dblink_get_pkey('foo');
|
||||||
|
@ -27,9 +27,6 @@ INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}');
|
|||||||
|
|
||||||
-- misc utilities
|
-- misc utilities
|
||||||
|
|
||||||
-- show the currently executing query
|
|
||||||
SELECT 'hello' AS hello, dblink_current_query() AS query;
|
|
||||||
|
|
||||||
-- list the primary key fields
|
-- list the primary key fields
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink_get_pkey('foo');
|
FROM dblink_get_pkey('foo');
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
/* $PostgreSQL: pgsql/contrib/dblink/uninstall_dblink.sql,v 1.5 2007/11/13 04:24:27 momjian Exp $ */
|
/* $PostgreSQL: pgsql/contrib/dblink/uninstall_dblink.sql,v 1.6 2008/04/04 16:57:21 momjian Exp $ */
|
||||||
|
|
||||||
-- Adjust this setting to control where the objects get dropped.
|
-- Adjust this setting to control where the objects get dropped.
|
||||||
SET search_path = public;
|
SET search_path = public;
|
||||||
|
|
||||||
DROP FUNCTION dblink_current_query ();
|
|
||||||
|
|
||||||
DROP FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text);
|
DROP FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text);
|
||||||
|
|
||||||
DROP FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text);
|
DROP FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/dblink.sgml,v 1.3 2007/12/06 04:12:09 tgl Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/dblink.sgml,v 1.4 2008/04/04 16:57:21 momjian Exp $ -->
|
||||||
|
|
||||||
<sect1 id="dblink">
|
<sect1 id="dblink">
|
||||||
<title>dblink</title>
|
<title>dblink</title>
|
||||||
@ -1346,49 +1346,6 @@ SELECT *
|
|||||||
</refsect1>
|
</refsect1>
|
||||||
</refentry>
|
</refentry>
|
||||||
|
|
||||||
<refentry id="CONTRIB-DBLINK-CURRENT-QUERY">
|
|
||||||
<refnamediv>
|
|
||||||
<refname>dblink_current_query</refname>
|
|
||||||
<refpurpose>returns the current query string</refpurpose>
|
|
||||||
</refnamediv>
|
|
||||||
|
|
||||||
<refsynopsisdiv>
|
|
||||||
<synopsis>
|
|
||||||
dblink_current_query() returns text
|
|
||||||
</synopsis>
|
|
||||||
</refsynopsisdiv>
|
|
||||||
|
|
||||||
<refsect1>
|
|
||||||
<title>Description</title>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Returns the currently executing interactive command string of the
|
|
||||||
local database session, or NULL if it can't be determined. Note
|
|
||||||
that this function is not really related to <filename>dblink</>'s
|
|
||||||
other functionality. It is provided since it is sometimes useful
|
|
||||||
in generating queries to be forwarded to remote databases.
|
|
||||||
</para>
|
|
||||||
</refsect1>
|
|
||||||
|
|
||||||
<refsect1>
|
|
||||||
<title>Return Value</title>
|
|
||||||
|
|
||||||
<para>Returns a copy of the currently executing query string.</para>
|
|
||||||
</refsect1>
|
|
||||||
|
|
||||||
<refsect1>
|
|
||||||
<title>Example</title>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
test=# select dblink_current_query();
|
|
||||||
dblink_current_query
|
|
||||||
--------------------------------
|
|
||||||
select dblink_current_query();
|
|
||||||
(1 row)
|
|
||||||
</programlisting>
|
|
||||||
</refsect1>
|
|
||||||
</refentry>
|
|
||||||
|
|
||||||
<refentry id="CONTRIB-DBLINK-GET-PKEY">
|
<refentry id="CONTRIB-DBLINK-GET-PKEY">
|
||||||
<refnamediv>
|
<refnamediv>
|
||||||
<refname>dblink_get_pkey</refname>
|
<refname>dblink_get_pkey</refname>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.425 2008/03/23 00:24:19 tgl Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.426 2008/04/04 16:57:21 momjian Exp $ -->
|
||||||
|
|
||||||
<chapter id="functions">
|
<chapter id="functions">
|
||||||
<title>Functions and Operators</title>
|
<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);
|
|||||||
<entry>user name of current execution context</entry>
|
<entry>user name of current execution context</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
|
<row>
|
||||||
|
<entry><literal><function>current_query</function></literal></entry>
|
||||||
|
<entry><type>text</type></entry>
|
||||||
|
<entry>text of the currently executing query (might contain more than one statement)</entry>
|
||||||
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><literal><function>inet_client_addr</function>()</literal></entry>
|
<entry><literal><function>inet_client_addr</function>()</literal></entry>
|
||||||
<entry><type>inet</type></entry>
|
<entry><type>inet</type></entry>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.58 2008/01/01 19:45:52 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.59 2008/04/04 16:57:21 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -29,6 +29,7 @@
|
|||||||
#include "storage/pmsignal.h"
|
#include "storage/pmsignal.h"
|
||||||
#include "storage/procarray.h"
|
#include "storage/procarray.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "tcop/tcopprot.h"
|
||||||
|
|
||||||
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
||||||
|
|
||||||
@ -71,6 +72,19 @@ current_database(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* current_query()
|
||||||
|
* Expose the current query to the user (useful in stored procedures)
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
current_query(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
if (debug_query_string)
|
||||||
|
PG_RETURN_TEXT_P(cstring_to_text(debug_query_string));
|
||||||
|
else
|
||||||
|
PG_RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions to send signals to other backends.
|
* Functions to send signals to other backends.
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.485 2008/03/27 03:57:34 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.486 2008/04/04 16:57:21 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The script catalog/genbki.sh reads this file and generates .bki
|
* The script catalog/genbki.sh reads this file and generates .bki
|
||||||
@ -1117,6 +1117,8 @@ DESCR("convert char to char()");
|
|||||||
|
|
||||||
DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 f f t f i 0 19 "" _null_ _null_ _null_ current_database - _null_ _null_ ));
|
DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 f f t f i 0 19 "" _null_ _null_ _null_ current_database - _null_ _null_ ));
|
||||||
DESCR("returns the current database");
|
DESCR("returns the current database");
|
||||||
|
DATA(insert OID = 817 ( current_query PGNSP PGUID 12 1 0 f f f f v 0 25 "" _null_ _null_ _null_ current_query - _null_ _null_ ));
|
||||||
|
DESCR("returns the currently executing query");
|
||||||
|
|
||||||
DATA(insert OID = 862 ( int4_mul_cash PGNSP PGUID 12 1 0 f f t f i 2 790 "23 790" _null_ _null_ _null_ int4_mul_cash - _null_ _null_ ));
|
DATA(insert OID = 862 ( int4_mul_cash PGNSP PGUID 12 1 0 f f t f i 2 790 "23 790" _null_ _null_ _null_ int4_mul_cash - _null_ _null_ ));
|
||||||
DESCR("multiply");
|
DESCR("multiply");
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.310 2008/03/25 22:42:45 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.311 2008/04/04 16:57:21 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -414,6 +414,7 @@ extern Datum pg_ls_dir(PG_FUNCTION_ARGS);
|
|||||||
extern Datum nullvalue(PG_FUNCTION_ARGS);
|
extern Datum nullvalue(PG_FUNCTION_ARGS);
|
||||||
extern Datum nonnullvalue(PG_FUNCTION_ARGS);
|
extern Datum nonnullvalue(PG_FUNCTION_ARGS);
|
||||||
extern Datum current_database(PG_FUNCTION_ARGS);
|
extern Datum current_database(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum current_query(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
|
extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
|
extern Datum pg_reload_conf(PG_FUNCTION_ARGS);
|
||||||
extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
|
extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user