Skip site navigation (1) Skip section navigation (2)

Re: BUG #4434: Error inserting into view - unrecognized node type: 313

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Dean Rasheed <dean_rasheed(at)hotmail(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4434: Error inserting into view - unrecognized node type: 313
Date: 2008-09-24 07:37:53
Message-ID: 48D9EE51.20701@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-bugs
Tom Lane wrote:
> "Dean Rasheed" <dean_rasheed(at)hotmail(dot)com> writes:
>> CREATE TABLE foo(a int, b int);
>> CREATE VIEW foo_v AS SELECT * FROM foo;
>> CREATE RULE foo_r AS ON INSERT TO foo_v DO INSTEAD INSERT INTO foo
>> VALUES(NEW.a, NEW.b);
>> INSERT INTO foo_v VALUES ((SELECT 1), (SELECT 2)), ((SELECT 3), (SELECT 4));
> 
>> ERROR:  unrecognized node type: 313
> 
> It looks like the parser's code path for multi-row VALUES is neglecting
> to detect sublinks and set pstate->p_hasSubLinks.  I'm too tired to look
> closer tonight; anyone want to poke into it?

I think the parser is OK, but the p_hasSubLinks is lost in the rewrite 
phase. In ResolveNew, we set p_hasSubLinks whenever a Var with a SubLink 
is found. In case of Values RTE, however, there's no Vars, but plain 
SubLink nodes. This patch seems to fix it:

--- src/backend/rewrite/rewriteManip.c
+++ src/backend/rewrite/rewriteManip.c
@@ -1112,6 +1112,12 @@ ResolveNew_mutator(Node *node, ResolveNew_context 
*context)
  		context->sublevels_up--;
  		return (Node *) newnode;
  	}
+	else if (IsA(node, SubLink))
+	{
+		/* Report it if we are adding a sublink to query */
+		context->inserted_sublink = true;
+		/* fall through to copy the expr normally */
+	}
  	return expression_tree_mutator(node, ResolveNew_mutator,
  								   (void *) context);
  }

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

In response to

Responses

pgsql-bugs by date

Next:From: Alex HunsakerDate: 2008-09-24 07:38:01
Subject: Re: BUG #4434: Error inserting into view - unrecognized node type: 313
Previous:From: Magnus HaganderDate: 2008-09-24 05:58:27
Subject: Re: [HACKERS] 0x1A in control file on Windows

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group