Index: src/backend/utils/adt/ruleutils.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v
retrieving revision 1.306
diff -c -r1.306 ruleutils.c
*** src/backend/utils/adt/ruleutils.c	1 Aug 2009 19:59:41 -0000	1.306
--- src/backend/utils/adt/ruleutils.c	21 Sep 2009 18:22:01 -0000
***************
*** 2648,2659 ****
  				TupleDesc resultDesc)
  {
  	StringInfo	buf = context->buf;
  	char	   *sep;
! 	int			colno;
  	ListCell   *l;
  
  	sep = " ";
  	colno = 0;
  	foreach(l, targetList)
  	{
  		TargetEntry *tle = (TargetEntry *) lfirst(l);
--- 2648,2671 ----
  				TupleDesc resultDesc)
  {
  	StringInfo	buf = context->buf;
+ 	StringInfoData sep_indent;
  	char	   *sep;
! 	int			colno, len;
  	ListCell   *l;
  
  	sep = " ";
  	colno = 0;
+ 
+ 	/* 
+ 	 * Separator to make each target appear on its own line, regardless 
+ 	 * of pretty printing.
+ 	 * Try to make them all line up at the same line position.
+ 	 */
+ 	initStringInfo(&sep_indent);
+ 	appendStringInfoString(&sep_indent,",\n ");
+ 	for (len = buf->len -1; len >= 0 && buf->data[len]!= '\n'; len--)
+ 		appendStringInfoChar(&sep_indent,' ');
+ 
  	foreach(l, targetList)
  	{
  		TargetEntry *tle = (TargetEntry *) lfirst(l);
***************
*** 2664,2670 ****
  			continue;			/* ignore junk entries */
  
  		appendStringInfoString(buf, sep);
! 		sep = ", ";
  		colno++;
  
  		/*
--- 2676,2682 ----
  			continue;			/* ignore junk entries */
  
  		appendStringInfoString(buf, sep);
! 		sep = sep_indent.data;
  		colno++;
  
  		/*
***************
*** 2704,2709 ****
--- 2716,2726 ----
  				appendStringInfo(buf, " AS %s", quote_identifier(colname));
  		}
  	}
+ 
+ 	if (colno > 1 && ! PRETTY_INDENT(context))
+ 		appendStringInfoChar(buf,'\n');
+ 
+ 	pfree(sep_indent.data);
  }
  
  static void
***************
*** 4595,4602 ****
  				CaseExpr   *caseexpr = (CaseExpr *) node;
  				ListCell   *temp;
  
! 				appendContextKeyword(context, "CASE",
! 									 0, PRETTYINDENT_VAR, 0);
  				if (caseexpr->arg)
  				{
  					appendStringInfoChar(buf, ' ');
--- 4612,4620 ----
  				CaseExpr   *caseexpr = (CaseExpr *) node;
  				ListCell   *temp;
  
! 				appendStringInfoString(buf,"CASE");
! 				if (PRETTY_INDENT(context))
! 					context->indentLevel += PRETTYINDENT_VAR;
  				if (caseexpr->arg)
  				{
  					appendStringInfoChar(buf, ' ');
