X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B6B43DBA19 for ; Wed, 23 Nov 2005 13:23:10 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43934-06 for ; Wed, 23 Nov 2005 17:23:09 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9A35EDBA1E for ; Wed, 23 Nov 2005 13:23:07 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jANHN0lr022946; Wed, 23 Nov 2005 12:23:00 -0500 (EST) To: Kyle Bateman cc: pgsql-sql@postgresql.org Subject: Re: unplanned sub-select error? In-reply-to: <43837E9B.20306@actarg.com> References: <43826850.1020302@actarg.com> <6603.1132621854@sss.pgh.pa.us> <43837E9B.20306@actarg.com> Comments: In-reply-to Kyle Bateman message dated "Tue, 22 Nov 2005 13:24:59 -0700" Date: Wed, 23 Nov 2005 12:23:00 -0500 Message-ID: <22945.1132766580@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.005 required=5 tests=[AWL=0.005] X-Spam-Score: 0.005 X-Spam-Level: X-Archive-Number: 200511/227 X-Sequence-Number: 23478 Kyle Bateman writes: > Sorry, you're right. I have now confirmed that this only happens when > updating via a view/rule (as you suspected). Attached is a minimalist > sql file that demonstrates the same error message from a blank > database. I'm using 8.1.0. I'm pretty sure this problem did not exist > on 8.0.3. Fixed --- attached is the patch if you need it right away. Thanks for the report! regards, tom lane Index: src/backend/rewrite/rewriteHandler.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v retrieving revision 1.159 diff -c -r1.159 rewriteHandler.c *** src/backend/rewrite/rewriteHandler.c 22 Nov 2005 18:17:19 -0000 1.159 --- src/backend/rewrite/rewriteHandler.c 23 Nov 2005 17:10:01 -0000 *************** *** 374,379 **** --- 374,387 ---- sub_action->jointree->fromlist = list_concat(newjointree, sub_action->jointree->fromlist); + + /* + * There could have been some SubLinks in newjointree, in which + * case we'd better mark the sub_action correctly. + */ + if (parsetree->hasSubLinks && !sub_action->hasSubLinks) + sub_action->hasSubLinks = + checkExprHasSubLink((Node *) newjointree); } } Index: src/backend/rewrite/rewriteManip.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v retrieving revision 1.93 diff -c -r1.93 rewriteManip.c *** src/backend/rewrite/rewriteManip.c 22 Nov 2005 18:17:19 -0000 1.93 --- src/backend/rewrite/rewriteManip.c 23 Nov 2005 17:10:01 -0000 *************** *** 930,935 **** --- 930,936 ---- RangeTblEntry *target_rte, List *targetlist, int event, int update_varno) { + Node *result; ResolveNew_context context; context.target_varno = target_varno; *************** *** 944,951 **** * Must be prepared to start with a Query or a bare expression tree; if * it's a Query, we don't want to increment sublevels_up. */ ! return query_or_expression_tree_mutator(node, ! ResolveNew_mutator, ! (void *) &context, ! 0); } --- 945,965 ---- * Must be prepared to start with a Query or a bare expression tree; if * it's a Query, we don't want to increment sublevels_up. */ ! result = query_or_expression_tree_mutator(node, ! ResolveNew_mutator, ! (void *) &context, ! 0); ! ! if (context.inserted_sublink) ! { ! if (IsA(result, Query)) ! ((Query *) result)->hasSubLinks = true; ! /* ! * Note: if we're called on a non-Query node then it's the caller's ! * responsibility to update hasSubLinks in the ancestor Query. ! * This is pretty fragile and perhaps should be rethought ... ! */ ! } ! ! return result; }