summaryrefslogtreecommitdiff
path: root/src/include/parser
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-09-09 03:33:01 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-09-09 03:33:01 +0000
commit9ed9ac5a38431cf328088657c4c82b63e6326aab (patch)
treef1e387d920e19b4d60d0ec607c137853c9dc99ef /src/include/parser
parent3385dcc8c8b395230d8b9d450f1d4e77bc43243f (diff)
Fix bug with WITH RECURSIVE immediately inside WITH RECURSIVE. 99% of the
code was already okay with this, but the hack that obtained the output column types of a recursive union in advance of doing real parse analysis of the recursive union forgot to handle the case where there was an inner WITH clause available to the non-recursive term. Best fix seems to be to refactor so that we don't need the "throwaway" parse analysis step at all. Instead, teach the transformSetOperationStmt code to set up the CTE's output column information after it's processed the non-recursive term normally. Per report from David Fetter.
Diffstat (limited to 'src/include/parser')
-rw-r--r--src/include/parser/analyze.h5
-rw-r--r--src/include/parser/parse_cte.h5
-rw-r--r--src/include/parser/parse_node.h6
3 files changed, 12 insertions, 4 deletions
diff --git a/src/include/parser/analyze.h b/src/include/parser/analyze.h
index a662e37b7af..63b1cf1d950 100644
--- a/src/include/parser/analyze.h
+++ b/src/include/parser/analyze.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.40 2009/01/01 17:24:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.40.2.1 2009/09/09 03:33:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,7 +22,8 @@ extern Query *parse_analyze(Node *parseTree, const char *sourceText,
extern Query *parse_analyze_varparams(Node *parseTree, const char *sourceText,
Oid **paramTypes, int *numParams);
-extern Query *parse_sub_analyze(Node *parseTree, ParseState *parentParseState);
+extern Query *parse_sub_analyze(Node *parseTree, ParseState *parentParseState,
+ CommonTableExpr *parentCTE);
extern Query *transformStmt(ParseState *pstate, Node *parseTree);
extern bool analyze_requires_snapshot(Node *parseTree);
diff --git a/src/include/parser/parse_cte.h b/src/include/parser/parse_cte.h
index b5dd11ec140..5a8209aaf86 100644
--- a/src/include/parser/parse_cte.h
+++ b/src/include/parser/parse_cte.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_cte.h,v 1.2 2009/01/01 17:24:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_cte.h,v 1.2.2.1 2009/09/09 03:33:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,4 +18,7 @@
extern List *transformWithClause(ParseState *pstate, WithClause *withClause);
+extern void analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte,
+ List *tlist);
+
#endif /* PARSE_CTE_H */
diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h
index 78b43d915a8..84a32b20835 100644
--- a/src/include/parser/parse_node.h
+++ b/src/include/parser/parse_node.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.62 2009/06/11 14:49:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/parser/parse_node.h,v 1.62.2.1 2009/09/09 03:33:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -61,6 +61,9 @@
* p_future_ctes: list of CommonTableExprs (WITH items) that are not yet
* visible due to scope rules. This is used to help improve error messages.
*
+ * p_parent_cte: CommonTableExpr that immediately contains the current query,
+ * if any.
+ *
* p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses.
* We collect these while transforming expressions and then transform them
* afterwards (so that any resjunk tlist items needed for the sort/group
@@ -88,6 +91,7 @@ typedef struct ParseState
List *p_varnamespace; /* current namespace for columns */
List *p_ctenamespace; /* current namespace for common table exprs */
List *p_future_ctes; /* common table exprs not yet in namespace */
+ CommonTableExpr *p_parent_cte; /* this query's containing CTE */
List *p_windowdefs; /* raw representations of window clauses */
Oid *p_paramtypes; /* OIDs of types for $n parameter symbols */
int p_numparams; /* allocated size of p_paramtypes[] */