Tom Lane wrote:
> Bruce Momjian <[email protected]> writes:
> > Tom Lane wrote:
> >> We should take a second look at the usage of debug_query_string,
> >> particularly the recently added current_query() SQL function.
>
> > I looked at the use of 'debug_query_string'; I didn't see how
> > current_query() could access the more concise query string that is
> > stored in various structures (comment added); it works now by accessing
> > the global variable 'debug_query_string'.
>
> The alternative I was envisioning was to have it look at the
> ActivePortal's query string. However, if you prefer to define the
> function as returning the current client query, it's fine as-is.
> We should make sure the documentation explains it like that however.
Oh, I certainly didn't like current_query() using 'debug_query_string'.
Now that you told me about ActivePortal I have used that and it seems to
work fine. Patch attached and applied; documentation updated.
--
Bruce Momjian <[email protected]> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.465
diff -c -c -r1.465 func.sgml
*** doc/src/sgml/func.sgml 31 Dec 2008 00:08:33 -0000 1.465
--- doc/src/sgml/func.sgml 7 Jan 2009 21:04:02 -0000
***************
*** 11343,11349 ****
<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>
--- 11343,11350 ----
<row>
<entry><literal><function>current_query</function></literal></entry>
<entry><type>text</type></entry>
! <entry>text of the currently executing query (might match
! client-supplied query or be internal query string)</entry>
</row>
<row>
Index: src/backend/utils/adt/misc.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v
retrieving revision 1.68
diff -c -c -r1.68 misc.c
*** src/backend/utils/adt/misc.c 7 Jan 2009 19:51:21 -0000 1.68
--- src/backend/utils/adt/misc.c 7 Jan 2009 21:04:02 -0000
***************
*** 31,36 ****
--- 31,37 ----
#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,69 ****
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();
}
/*
--- 60,66 ----
Datum
current_query(PG_FUNCTION_ARGS)
{
! PG_RETURN_TEXT_P(cstring_to_text(ActivePortal->sourceText));
}
/*
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers