Hi,

Hopefully nobody minds if I slip this to the commit fest that started today? The attached patch should address all the comments from the 9.5 cycle.


.m
*** a/src/backend/parser/analyze.c
--- b/src/backend/parser/analyze.c
***************
*** 2107,2118 **** transformUpdateTargetList(ParseState *pstate, List 
*origTlist)
                attrno = attnameAttNum(pstate->p_target_relation,
                                                           origTarget->name, 
true);
                if (attrno == InvalidAttrNumber)
                        ereport(ERROR,
                                        (errcode(ERRCODE_UNDEFINED_COLUMN),
                                         errmsg("column \"%s\" of relation 
\"%s\" does not exist",
                                                        origTarget->name,
!                                                
RelationGetRelationName(pstate->p_target_relation)),
                                         parser_errposition(pstate, 
origTarget->location)));
  
                updateTargetListEntry(pstate, tle, origTarget->name,
                                                          attrno,
--- 2107,2136 ----
                attrno = attnameAttNum(pstate->p_target_relation,
                                                           origTarget->name, 
true);
                if (attrno == InvalidAttrNumber)
+               {
+                       bool need_hint = false;
+ 
+                       /*
+                        * Table-qualifying the LHS expression in SET is a 
common mistake;
+                        * provide a hint if that seems to be the problem.
+                        */
+                       if (origTarget->indirection != NIL &&
+                               IsA(linitial(origTarget->indirection), String))
+                       {
+                               if (strcmp(origTarget->name, 
RelationGetRelationName(pstate->p_target_relation)) == 0)
+                                       need_hint = true;
+                               else if (target_rte->alias && 
strcmp(origTarget->name, target_rte->alias->aliasname) == 0)
+                                       need_hint = true;
+                       }
+ 
                        ereport(ERROR,
                                        (errcode(ERRCODE_UNDEFINED_COLUMN),
                                         errmsg("column \"%s\" of relation 
\"%s\" does not exist",
                                                        origTarget->name,
!                                                       
RelationGetRelationName(pstate->p_target_relation)),
!                                        need_hint ? errhint("Do not qualify an 
UPDATE target column with the name of the table.") : 0,
                                         parser_errposition(pstate, 
origTarget->location)));
+               }
  
                updateTargetListEntry(pstate, tle, origTarget->name,
                                                          attrno,
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to