Commits

Andrew Dunstan committed ff9bbd2

Also wrap FROM clause items.

  • Participants
  • Parent commits 83a674a
  • Branches viewdefs

Comments (0)

Files changed (1)

src/backend/utils/adt/ruleutils.c

 			appendContextKeyword(context, prefix,
 								 -PRETTYINDENT_STD, PRETTYINDENT_STD, 2);
 			first = false;
+
+			get_from_clause_item(jtnode, query, context);
 		}
 		else
+		{
+			StringInfoData targetbuf;
+			char          *trailing_nl;
+
 			appendStringInfoString(buf, ", ");
+			
+			initStringInfo(&targetbuf);
+			context->buf = &targetbuf;
+
+			get_from_clause_item(jtnode, query, context);
+
+			context->buf = buf;
+
+			/* Locate the start of the current  line in the buffer */
+
+			trailing_nl = (strrchr(buf->data,'\n'));
+			if (trailing_nl == NULL)
+				trailing_nl = buf->data;
+			else 
+				trailing_nl++;
+			
+			/*
+			 * Add a newline, plus some  indentation, if pretty_wrap is on and the 
+			 * new from-clause item would cause an overflow.
+			 */
+			
+			if (pretty_wrap >= 0 &&
+				(strlen(trailing_nl) + strlen(targetbuf.data) > pretty_wrap))
+			{
+				appendContextKeyword(context, "", -PRETTYINDENT_STD, 
+									 PRETTYINDENT_STD, PRETTYINDENT_VAR);
+			}
+
+			/* Add the new item */
+
+			appendStringInfoString(buf, targetbuf.data);
+			
+			/* cleanup */
+
+			pfree (targetbuf.data);
+		}
 
-		get_from_clause_item(jtnode, query, context);
 	}
 }