aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_target.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-10-05 22:20:17 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-10-05 22:20:17 +0000
commit08142504743bc79feb233f42ae24246273102813 (patch)
treed6c8148d0fe6318f27f82f3c50045cf0e8f77d58 /src/backend/parser/parse_target.c
parent6151e89e8bdd458b36ff7571b2dc7bf5b03ae3cb (diff)
downloadpostgresql-08142504743bc79feb233f42ae24246273102813.tar.gz
postgresql-08142504743bc79feb233f42ae24246273102813.zip
Fix markTargetListOrigin() to not fail on a simple-Var reference to a
recursive CTE that we're still in progress of analyzing. Add a similar guard to the similar code in expandRecordVariable(), and tweak regression tests to cover this case. Per report from Dickson S. Guedes.
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r--src/backend/parser/parse_target.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 3ead26194e3..ed54abe7039 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.165 2008/10/04 21:56:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.166 2008/10/05 22:20:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -297,8 +297,16 @@ markTargetListOrigin(ParseState *pstate, TargetEntry *tle,
/* not a simple relation, leave it unmarked */
break;
case RTE_CTE:
- /* CTE reference: copy up from the subquery */
- if (attnum != InvalidAttrNumber)
+ /*
+ * CTE reference: copy up from the subquery, if possible.
+ * If the RTE is a recursive self-reference then we can't do
+ * anything because we haven't finished analyzing it yet.
+ * However, it's no big loss because we must be down inside
+ * the recursive term of a recursive CTE, and so any markings
+ * on the current targetlist are not going to affect the results
+ * anyway.
+ */
+ if (attnum != InvalidAttrNumber && !rte->self_reference)
{
CommonTableExpr *cte = GetCTEForRTE(pstate, rte);
TargetEntry *ste;
@@ -1195,8 +1203,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
*/
break;
case RTE_CTE:
+ /* CTE reference: examine subquery's output expr */
+ if (!rte->self_reference)
{
- /* CTE reference: examine subquery's output expr */
CommonTableExpr *cte = GetCTEForRTE(pstate, rte);
TargetEntry *ste;