On mån, 2010-01-11 at 12:54 -0500, Tom Lane wrote:
> Peter Eisentraut <pete...@gmx.net> writes:
> > On mån, 2010-01-11 at 10:44 -0500, Tom Lane wrote:
> >> I think you could probably use the existing tag field; no need for a new
> >> one.
> 
> > Sorry, which tag field are you referring to?
> 
> The one called "tag" in the source code.  It prints out as "Name":
> 
> --
> -- Name: binary_coercible(oid, oid); Type: FUNCTION; Schema: public; Owner: 
> postgres
>          ^^^^^^^^^^^^^^^^^^^^^^^^^^
> --

Um, that tag is the "name", and if you change that, the name in CREATE
FUNCTION also changes.  I was initially thinking in that direction, but
it seems it won't be feasible without significant refactoring.

In the mean time, hacking it into the sort function itself as a special
case works out fine, per attached patch.  One might frown upon such an
exception, but then again, function overloading is an exception to the
one-name-per-object rule all over the place anyway. ;-)
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 6676baf..84f68c9 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -163,7 +163,26 @@ DOTypeNameCompare(const void *p1, const void *p2)
 	if (cmpval != 0)
 		return cmpval;
 
-	/* Probably shouldn't get here, but if we do, sort by OID */
+	/* To have a stable sort order, break ties for some object types */
+    if (obj1->objType == DO_FUNC || obj1->objType == DO_AGG)
+	{
+		FuncInfo *fobj1 = *(FuncInfo **) p1;
+		FuncInfo *fobj2 = *(FuncInfo **) p2;
+		int i;
+
+		cmpval = fobj1->nargs - fobj2->nargs;
+		if (cmpval != 0)
+			return cmpval;
+
+		for (i = 0; i < fobj1->nargs; i++)
+		{
+			cmpval = oidcmp(fobj1->argtypes[i], fobj2->argtypes[i]);
+			if (cmpval != 0)
+				return cmpval;
+		}
+	}
+
+	/* Usually shouldn't get here, but if we do, sort by OID */
 	return oidcmp(obj1->catId.oid, obj2->catId.oid);
 }
 
-- 
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