Fix longstanding oversight in ruleutils.c: it doesn't regurgitate
authorTom Lane <[email protected]>
Mon, 30 May 2005 01:57:27 +0000 (01:57 +0000)
committerTom Lane <[email protected]>
Mon, 30 May 2005 01:57:27 +0000 (01:57 +0000)
a FOR UPDATE clause, if one is present.

src/backend/utils/adt/ruleutils.c

index 0a3b9c60a0268fe668558c89632239c794b89815..e7808c1778456c5f5ae39e5e483bbc078c0bba1a 100644 (file)
@@ -1919,6 +1919,28 @@ get_select_query_def(Query *query, deparse_context *context,
                else
                        get_rule_expr(query->limitCount, context, false);
        }
+
+       /* Add the FOR UPDATE/SHARE clause if present */
+       if (query->rowMarks != NIL)
+       {
+               if (query->forUpdate)
+                       appendContextKeyword(context, " FOR UPDATE OF ",
+                                                                -PRETTYINDENT_STD, PRETTYINDENT_STD, 0);
+               else
+                       appendContextKeyword(context, " FOR SHARE OF ",
+                                                                -PRETTYINDENT_STD, PRETTYINDENT_STD, 0);
+               sep = "";
+               foreach(l, query->rowMarks)
+               {
+                       int                     rtindex = lfirst_int(l);
+                       RangeTblEntry *rte = rt_fetch(rtindex, query->rtable);
+
+                       appendStringInfo(buf, "%s%s",
+                                                        sep,
+                                                        quote_identifier(rte->eref->aliasname));
+                       sep = ", ";
+               }
+       }
 }
 
 static void