Have current_query() use ActivePortal->sourceText rather than
authorBruce Momjian <bruce@momjian.us>
Wed, 7 Jan 2009 21:48:15 +0000 (21:48 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 7 Jan 2009 21:48:15 +0000 (21:48 +0000)
debug_query_string;  this allows current_query() to be more accurate;
docs updated;  per idea from Tom

doc/src/sgml/func.sgml
src/backend/utils/adt/misc.c

index bf3293a0cf258192fc0b5636f164ca6dd3247651..897762f6e6987c132df534153d4e7f9e6cdbd4bf 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.465 2008/12/31 00:08:33 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.466 2009/01/07 21:48:15 momjian Exp $ -->
 
  <chapter id="functions">
   <title>Functions and Operators</title>
@@ -11343,7 +11343,8 @@ postgres=# select * from unnest2(array[[1,2],[3,4]]);
       <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>
+       <entry>text of the currently executing query (might match
+         client-supplied query or be internal query string)</entry>
       </row>  
 
       <row>
index 2042f96f82aeea8d8645408860ef9ffc4f56fa09..bc068932e9d88555046481f28b19584c7f558494 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.68 2009/01/07 19:51:21 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.69 2009/01/07 21:48:15 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,7 @@
 #include "storage/pmsignal.h"
 #include "storage/procarray.h"
 #include "utils/builtins.h"
+#include "tcop/pquery.h"
 #include "tcop/tcopprot.h"
 
 #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
@@ -59,11 +60,7 @@ current_database(PG_FUNCTION_ARGS)
 Datum
 current_query(PG_FUNCTION_ARGS)
 {
-   /* there is no easy way to access the more concise 'query_string' */
-   if (debug_query_string)
-       PG_RETURN_TEXT_P(cstring_to_text(debug_query_string));
-   else
-       PG_RETURN_NULL();
+   PG_RETURN_TEXT_P(cstring_to_text(ActivePortal->sourceText));
 }
 
 /*