diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index a661556ba9..2466ba7cee 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -308,6 +308,8 @@ appendQualifiedRelation(PQExpBuffer buf, const char *spec,
 	PGresult   *res;
 	int			ntups;
 
+	initPQExpBuffer(&sql);
+
 	/* Before 7.3, the concept of qualifying a name did not exist. */
 	if (PQserverVersion(conn) < 70300)
 	{
@@ -322,7 +324,6 @@ appendQualifiedRelation(PQExpBuffer buf, const char *spec,
 	 * be unnecessary given a regclassin() variant taking a search_path
 	 * argument.
 	 */
-	initPQExpBuffer(&sql);
 	appendPQExpBufferStr(&sql,
 						 "SELECT c.relname, ns.nspname\n"
 						 " FROM pg_catalog.pg_class c,"
