Index: contrib/dblink/dblink.c =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/dblink.c,v retrieving revision 1.63 diff -c -r1.63 dblink.c *** contrib/dblink/dblink.c 6 Apr 2007 04:21:41 -0000 1.63 --- contrib/dblink/dblink.c 10 May 2007 01:57:30 -0000 *************** *** 1630,1652 **** PG_RETURN_TEXT_P(GET_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(GET_TEXT(debug_query_string)); - else - PG_RETURN_NULL(); - } - - /************************************************************* * internal functions */ --- 1630,1635 ---- Index: contrib/dblink/dblink.h =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/dblink.h,v retrieving revision 1.18 diff -c -r1.18 dblink.h *** contrib/dblink/dblink.h 5 Jan 2007 22:19:17 -0000 1.18 --- contrib/dblink/dblink.h 10 May 2007 01:57:30 -0000 *************** *** 56,61 **** 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 */ --- 56,60 ---- Index: contrib/dblink/dblink.sql.in =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/dblink.sql.in,v retrieving revision 1.11 diff -c -r1.11 dblink.sql.in *** contrib/dblink/dblink.sql.in 2 Sep 2006 21:11:15 -0000 1.11 --- contrib/dblink/dblink.sql.in 10 May 2007 01:57:30 -0000 *************** *** 140,150 **** 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' --- 140,145 ---- Index: contrib/dblink/uninstall_dblink.sql =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/uninstall_dblink.sql,v retrieving revision 1.3 diff -c -r1.3 uninstall_dblink.sql *** contrib/dblink/uninstall_dblink.sql 11 Sep 2006 02:10:26 -0000 1.3 --- contrib/dblink/uninstall_dblink.sql 10 May 2007 01:57:30 -0000 *************** *** 1,5 **** - 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); --- 1,3 ---- Index: contrib/dblink/doc/misc =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/doc/misc,v retrieving revision 1.4 diff -c -r1.4 misc *** contrib/dblink/doc/misc 2 Sep 2006 21:11:15 -0000 1.4 --- contrib/dblink/doc/misc 10 May 2007 01:57:30 -0000 *************** *** 2,32 **** ================================================================== Name - dblink_current_query -- returns the current query string - - Synopsis - - dblink_current_query () RETURNS text - - Inputs - - None - - Outputs - - Returns text -- a copy of the currently executing query - - Example usage - - test=# select dblink_current_query() from (select dblink('dbname=postgres','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; - dblink_current_query - ----------------------------------------------------------------------------------------------------------------------------------------------------- - select dblink_current_query() from (select dblink('dbname=postgres','select oid, proname from pg_proc where proname = ''byteacat''') as f1) as t1; - (1 row) - - ================================================================== - Name - dblink_get_pkey -- returns the position and field names of a relation's primary key fields --- 2,7 ---- Index: contrib/dblink/expected/dblink.out =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/expected/dblink.out,v retrieving revision 1.19 diff -c -r1.19 dblink.out *** contrib/dblink/expected/dblink.out 1 Feb 2007 21:05:29 -0000 1.19 --- contrib/dblink/expected/dblink.out 10 May 2007 01:57:31 -0000 *************** *** 21,30 **** 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 --- 21,30 ---- INSERT INTO foo VALUES (9,'j','{"a9","b9","c9"}'); -- misc utilities -- show the currently executing query ! SELECT 'hello' AS hello, current_query() AS query; hello | query ! -------+---------------------------------------------------- ! hello | SELECT 'hello' AS hello, current_query() AS query; (1 row) -- list the primary key fields Index: contrib/dblink/sql/dblink.sql =================================================================== RCS file: /projects/cvsroot/pgsql/contrib/dblink/sql/dblink.sql,v retrieving revision 1.16 diff -c -r1.16 dblink.sql *** contrib/dblink/sql/dblink.sql 2 Sep 2006 21:11:15 -0000 1.16 --- contrib/dblink/sql/dblink.sql 10 May 2007 01:57:31 -0000 *************** *** 26,32 **** -- misc utilities -- show the currently executing query ! SELECT 'hello' AS hello, dblink_current_query() AS query; -- list the primary key fields SELECT * --- 26,32 ---- -- misc utilities -- show the currently executing query ! SELECT 'hello' AS hello, current_query() AS query; -- list the primary key fields SELECT * Index: doc/TODO =================================================================== RCS file: /projects/cvsroot/pgsql/doc/TODO,v retrieving revision 1.2180 diff -c -r1.2180 TODO *** doc/TODO 5 May 2007 15:40:01 -0000 1.2180 --- doc/TODO 10 May 2007 01:57:33 -0000 *************** *** 1436,1442 **** * Remove or relicense modules that are not under the BSD license, if possible * %Remove memory/file descriptor freeing before ereport(ERROR) * Acquire lock on a relation before building a relcache entry for it - * %Promote debug_query_string into a server-side function current_query() * Allow cross-compiling by generating the zic database on the target system * Improve NLS maintenance of libpgport messages linked onto applications * Allow ecpg to work with MSVC and BCC --- 1436,1441 ---- Index: doc/src/FAQ/TODO.html =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/FAQ/TODO.html,v retrieving revision 1.681 diff -c -r1.681 TODO.html *** doc/src/FAQ/TODO.html 5 May 2007 15:40:01 -0000 1.681 --- doc/src/FAQ/TODO.html 10 May 2007 01:57:34 -0000 *************** *** 1278,1284 ****
  • Remove or relicense modules that are not under the BSD license, if possible
  • %Remove memory/file descriptor freeing before ereport(ERROR)
  • Acquire lock on a relation before building a relcache entry for it -
  • %Promote debug_query_string into a server-side function current_query()
  • Allow cross-compiling by generating the zic database on the target system
  • Improve NLS maintenance of libpgport messages linked onto applications
  • Allow ecpg to work with MSVC and BCC --- 1278,1283 ---- Index: doc/src/sgml/func.sgml =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.379 diff -c -r1.379 func.sgml *** doc/src/sgml/func.sgml 7 May 2007 07:53:26 -0000 1.379 --- doc/src/sgml/func.sgml 10 May 2007 01:57:43 -0000 *************** *** 10233,10238 **** --- 10233,10244 ---- + current_query + text + text of the current client query (not SPI queries or similar) + + + inet_client_addr() inet address of the remote connection Index: src/backend/utils/adt/misc.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/misc.c,v retrieving revision 1.56 diff -c -r1.56 misc.c *** src/backend/utils/adt/misc.c 5 Jan 2007 22:19:41 -0000 1.56 --- src/backend/utils/adt/misc.c 10 May 2007 01:57:44 -0000 *************** *** 29,34 **** --- 29,35 ---- #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,77 **** --- 73,99 ---- /* + * current_query() + * Expose the current query to the user (useful in stored procedures) + */ + Datum + current_query(PG_FUNCTION_ARGS) + { + int len; + text *result; + + if (debug_query_string) + { + result = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(debug_query_string))); + PG_RETURN_TEXT_P(result); + } + else + { + PG_RETURN_NULL(); + } + } + + /* * Functions to send signals to other backends. */ static bool Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v retrieving revision 1.454 diff -c -r1.454 pg_proc.h *** src/include/catalog/pg_proc.h 2 Apr 2007 03:49:40 -0000 1.454 --- src/include/catalog/pg_proc.h 10 May 2007 01:57:51 -0000 *************** *** 1142,1147 **** --- 1142,1149 ---- DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 f f t f i 0 19 "" _null_ _null_ _null_ current_database - _null_ )); DESCR("returns the current database"); + DATA(insert OID = 3534 ( current_query PGNSP PGUID 12 1 0 f f f f s 0 25 "" _null_ _null_ _null_ current_query - _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_ )); DESCR("multiply"); Index: src/include/utils/builtins.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/utils/builtins.h,v retrieving revision 1.291 diff -c -r1.291 builtins.h *** src/include/utils/builtins.h 2 Apr 2007 03:49:41 -0000 1.291 --- src/include/utils/builtins.h 10 May 2007 01:57:53 -0000 *************** *** 421,426 **** --- 421,427 ---- 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);