diff options
author | Bruce Momjian | 2008-04-04 16:57:21 +0000 |
---|---|---|
committer | Bruce Momjian | 2008-04-04 16:57:21 +0000 |
commit | eda8c8afbfc53f67273cb6a6c6d9c24a1f41f630 (patch) | |
tree | 8f23824d8af0983fc166d1dd9bf1ba5154da0d11 | |
parent | c59b3faaab4663337eadd163b72408b74e484135 (diff) |
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
-rw-r--r-- | contrib/dblink/dblink.c | 17 | ||||
-rw-r--r-- | contrib/dblink/dblink.h | 1 | ||||
-rw-r--r-- | contrib/dblink/dblink.sql.in | 5 | ||||
-rw-r--r-- | contrib/dblink/expected/dblink.out | 7 | ||||
-rw-r--r-- | contrib/dblink/sql/dblink.sql | 3 | ||||
-rw-r--r-- | contrib/dblink/uninstall_dblink.sql | 2 | ||||
-rw-r--r-- | doc/src/sgml/dblink.sgml | 43 | ||||
-rw-r--r-- | doc/src/sgml/func.sgml | 6 | ||||
-rw-r--r-- | src/backend/utils/adt/misc.c | 14 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 2 | ||||
-rw-r--r-- | src/include/utils/builtins.h | 1 |
11 files changed, 23 insertions, 78 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 863dd976d9..51d5a12691 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -1631,23 +1631,6 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) 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 */ diff --git a/contrib/dblink/dblink.h b/contrib/dblink/dblink.h index 706faf4c75..81be7e45fc 100644 --- a/contrib/dblink/dblink.h +++ b/contrib/dblink/dblink.h @@ -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_delete(PG_FUNCTION_ARGS); extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS); -extern Datum dblink_current_query(PG_FUNCTION_ARGS); #endif /* DBLINK_H */ diff --git a/contrib/dblink/dblink.sql.in b/contrib/dblink/dblink.sql.in index c72a87e458..cb4ab8cae3 100644 --- a/contrib/dblink/dblink.sql.in +++ b/contrib/dblink/dblink.sql.in @@ -163,11 +163,6 @@ RETURNS text AS 'MODULE_PATHNAME','dblink_build_sql_update' 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) RETURNS int4 AS 'MODULE_PATHNAME', 'dblink_send_query' diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out index fd35d76af9..ec5284daf4 100644 --- a/contrib/dblink/expected/dblink.out +++ b/contrib/dblink/expected/dblink.out @@ -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 (9,'j','{"a9","b9","c9"}'); -- 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 SELECT * FROM dblink_get_pkey('foo'); diff --git a/contrib/dblink/sql/dblink.sql b/contrib/dblink/sql/dblink.sql index 48e1daca54..1d5f962db8 100644 --- a/contrib/dblink/sql/dblink.sql +++ b/contrib/dblink/sql/dblink.sql @@ -27,9 +27,6 @@ INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}'); -- misc utilities --- show the currently executing query -SELECT 'hello' AS hello, dblink_current_query() AS query; - -- list the primary key fields SELECT * FROM dblink_get_pkey('foo'); diff --git a/contrib/dblink/uninstall_dblink.sql b/contrib/dblink/uninstall_dblink.sql index fa16e3dbd6..162b484a34 100644 --- a/contrib/dblink/uninstall_dblink.sql +++ b/contrib/dblink/uninstall_dblink.sql @@ -3,8 +3,6 @@ -- Adjust this setting to control where the objects get dropped. 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_delete (text, int2vector, int4, _text); diff --git a/doc/src/sgml/dblink.sgml b/doc/src/sgml/dblink.sgml index 5fdc6a729e..9bd5b0445d 100644 --- a/doc/src/sgml/dblink.sgml +++ b/doc/src/sgml/dblink.sgml @@ -1346,49 +1346,6 @@ SELECT * </refsect1> </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"> <refnamediv> <refname>dblink_get_pkey</refname> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index f0f3ee84cd..8326e88292 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -10725,6 +10725,12 @@ select current_date + s.a as dates from generate_series(0,14,7) as s(a); </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> <entry><literal><function>inet_client_addr</function>()</literal></entry> <entry><type>inet</type></entry> <entry>address of the remote connection</entry> diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 82bc8308cf..0d58053969 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -29,6 +29,7 @@ #include "storage/pmsignal.h" #include "storage/procarray.h" #include "utils/builtins.h" +#include "tcop/tcopprot.h" #define atooid(x) ((Oid) strtoul((x), NULL, 10)) @@ -72,6 +73,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. */ static bool diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 23484149bb..8354fd7d6b 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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_ )); 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_ )); DESCR("multiply"); diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index adc9760d4f..253fff29ee 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -414,6 +414,7 @@ extern Datum pg_ls_dir(PG_FUNCTION_ARGS); extern Datum nullvalue(PG_FUNCTION_ARGS); extern Datum nonnullvalue(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_reload_conf(PG_FUNCTION_ARGS); extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS); |