Still to be done: fix docs and fix regression failures under auto_explain.
  * Copyright (c) 2008-2010, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.12 2010/01/06 18:07:19 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.13 2010/02/16 22:19:59 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
            es.format = auto_explain_log_format;
 
            ExplainBeginOutput(&es);
+           ExplainQueryText(&es, queryDesc);
            ExplainPrintPlan(&es, queryDesc);
            ExplainEndOutput(&es);
 
             */
            ereport(LOG,
                    (errmsg("duration: %.3f ms  plan:\n%s",
-                           msec, es.str->data)));
+                           msec, es.str->data),
+                       errhidestmt(true)));
 
            pfree(es.str->data);
        }
 
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.202 2010/02/16 20:07:13 stark Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.203 2010/02/16 22:19:59 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
                NULL, NULL, NULL, es);
 }
 
+/*
+ * ExplainQueryText -
+ *    add a "Query Text" node that contains the actual text of the query
+ * 
+ * The caller should have set up the options fields of *es, as well as
+ * initializing the output buffer es->str. 
+ *
+ */
+void
+ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
+{
+   if (queryDesc->sourceText)
+       ExplainPropertyText("Query Text", queryDesc->sourceText, es);
+}
+
 /*
  * report_triggers -
  *     report execution stats for a single relation's triggers
 
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.45 2010/01/02 16:58:03 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.46 2010/02/16 22:19:59 adunstan Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
 
+extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
+
 extern void ExplainBeginOutput(ExplainState *es);
 extern void ExplainEndOutput(ExplainState *es);
 extern void ExplainSeparatePlans(ExplainState *es);