Attached patch puts the "metadata" about a function, especially the
language name, at the top of the CREATE FUNCTION statement, above the
possibly long, multi-line function definition.

-- 
Greg Sabino Mullane

Index: pg_dump.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.492
diff -c -r1.492 pg_dump.c
*** pg_dump.c	16 May 2008 23:36:05 -0000	1.492
--- pg_dump.c	12 Jun 2008 13:07:28 -0000
***************
*** 6775,6784 ****
  	rettypename = getFormattedTypeName(finfo->prorettype, zeroAsOpaque);
  
  	appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcsig);
! 	appendPQExpBuffer(q, "RETURNS %s%s\n    %s\n    LANGUAGE %s",
  					  (proretset[0] == 't') ? "SETOF " : "",
  					  rettypename,
- 					  asPart->data,
  					  fmtId(lanname));
  
  	free(rettypename);
--- 6775,6783 ----
  	rettypename = getFormattedTypeName(finfo->prorettype, zeroAsOpaque);
  
  	appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcsig);
! 	appendPQExpBuffer(q, "RETURNS %s%s\n    LANGUAGE %s\n",
  					  (proretset[0] == 't') ? "SETOF " : "",
  					  rettypename,
  					  fmtId(lanname));
  
  	free(rettypename);
***************
*** 6786,6794 ****
  	if (provolatile[0] != PROVOLATILE_VOLATILE)
  	{
  		if (provolatile[0] == PROVOLATILE_IMMUTABLE)
! 			appendPQExpBuffer(q, " IMMUTABLE");
  		else if (provolatile[0] == PROVOLATILE_STABLE)
! 			appendPQExpBuffer(q, " STABLE");
  		else if (provolatile[0] != PROVOLATILE_VOLATILE)
  		{
  			write_msg(NULL, "unrecognized provolatile value for function \"%s\"\n",
--- 6785,6793 ----
  	if (provolatile[0] != PROVOLATILE_VOLATILE)
  	{
  		if (provolatile[0] == PROVOLATILE_IMMUTABLE)
! 			appendPQExpBuffer(q, "    IMMUTABLE\n");
  		else if (provolatile[0] == PROVOLATILE_STABLE)
! 			appendPQExpBuffer(q, "    STABLE\n");
  		else if (provolatile[0] != PROVOLATILE_VOLATILE)
  		{
  			write_msg(NULL, "unrecognized provolatile value for function \"%s\"\n",
***************
*** 6798,6807 ****
  	}
  
  	if (proisstrict[0] == 't')
! 		appendPQExpBuffer(q, " STRICT");
  
  	if (prosecdef[0] == 't')
! 		appendPQExpBuffer(q, " SECURITY DEFINER");
  
  	/*
  	 * COST and ROWS are emitted only if present and not default, so as not to
--- 6797,6806 ----
  	}
  
  	if (proisstrict[0] == 't')
! 		appendPQExpBuffer(q, "    STRICT\n");
  
  	if (prosecdef[0] == 't')
! 		appendPQExpBuffer(q, "    SECURITY DEFINER\n");
  
  	/*
  	 * COST and ROWS are emitted only if present and not default, so as not to
***************
*** 6814,6831 ****
  		{
  			/* default cost is 1 */
  			if (strcmp(procost, "1") != 0)
! 				appendPQExpBuffer(q, " COST %s", procost);
  		}
  		else
  		{
  			/* default cost is 100 */
  			if (strcmp(procost, "100") != 0)
! 				appendPQExpBuffer(q, " COST %s", procost);
  		}
  	}
  	if (proretset[0] == 't' &&
  		strcmp(prorows, "0") != 0 && strcmp(prorows, "1000") != 0)
! 		appendPQExpBuffer(q, " ROWS %s", prorows);
  
  	for (i = 0; i < nconfigitems; i++)
  	{
--- 6813,6830 ----
  		{
  			/* default cost is 1 */
  			if (strcmp(procost, "1") != 0)
! 				appendPQExpBuffer(q, "    COST %s\n", procost);
  		}
  		else
  		{
  			/* default cost is 100 */
  			if (strcmp(procost, "100") != 0)
! 				appendPQExpBuffer(q, "   COST %s\n", procost);
  		}
  	}
  	if (proretset[0] == 't' &&
  		strcmp(prorows, "0") != 0 && strcmp(prorows, "1000") != 0)
! 		appendPQExpBuffer(q, "   ROWS %s\n", prorows);
  
  	for (i = 0; i < nconfigitems; i++)
  	{
***************
*** 6837,6843 ****
  		if (pos == NULL)
  			continue;
  		*pos++ = '\0';
! 		appendPQExpBuffer(q, "\n    SET %s TO ", fmtId(configitem));
  
  		/*
  		 * Some GUC variable names are 'LIST' type and hence must not be
--- 6836,6842 ----
  		if (pos == NULL)
  			continue;
  		*pos++ = '\0';
! 		appendPQExpBuffer(q, "    SET %s TO ", fmtId(configitem));
  
  		/*
  		 * Some GUC variable names are 'LIST' type and hence must not be
***************
*** 6848,6856 ****
  			appendPQExpBuffer(q, "%s", pos);
  		else
  			appendStringLiteralAH(q, pos, fout);
  	}
  
! 	appendPQExpBuffer(q, ";\n");
  
  	ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
  				 funcsig_tag,
--- 6847,6857 ----
  			appendPQExpBuffer(q, "%s", pos);
  		else
  			appendStringLiteralAH(q, pos, fout);
+ 
+ 		appendPQExpBuffer(q, "\n");
  	}
  
! 	appendPQExpBuffer(q, "    %s;\n", asPart->data);
  
  	ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
  				 funcsig_tag,
-- 
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

Reply via email to