66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 *
9- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.90 2007/02/10 14:58:55 petere Exp $
9+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.91 2007/05/15 20:20:21 alvherre Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -702,8 +702,8 @@ dumpRoleMembership(PGconn *conn)
702702
703703res = executeQuery (conn ,"SELECT ur.rolname AS roleid, "
704704"um.rolname AS member, "
705- "ug.rolname AS grantor , "
706- "a.admin_option "
705+ "a.admin_option , "
706+ "ug.rolname AS grantor "
707707"FROM pg_auth_members a "
708708"LEFT JOIN pg_authid ur on ur.oid = a.roleid "
709709"LEFT JOIN pg_authid um on um.oid = a.member "
@@ -717,14 +717,24 @@ dumpRoleMembership(PGconn *conn)
717717{
718718char * roleid = PQgetvalue (res ,i ,0 );
719719char * member = PQgetvalue (res ,i ,1 );
720- char * grantor = PQgetvalue (res ,i ,2 );
721- char * option = PQgetvalue (res ,i ,3 );
720+ char * option = PQgetvalue (res ,i ,2 );
722721
723722fprintf (OPF ,"GRANT %s" ,fmtId (roleid ));
724723fprintf (OPF ," TO %s" ,fmtId (member ));
725724if (* option == 't' )
726725fprintf (OPF ," WITH ADMIN OPTION" );
727- fprintf (OPF ," GRANTED BY %s;\n" ,fmtId (grantor ));
726+
727+ /*
728+ * We don't track the grantor very carefully in the backend, so cope
729+ * with the possibility that it has been dropped.
730+ */
731+ if (!PQgetisnull (res ,i ,3 ))
732+ {
733+ char * grantor = PQgetvalue (res ,i ,3 );
734+
735+ fprintf (OPF ," GRANTED BY %s" ,fmtId (grantor ));
736+ }
737+ fprintf (OPF ,";\n" );
728738}
729739
730740PQclear (res );