pg_dumpall: simplify coding of dropDBs()

There's no need for a StringInfo when all you want is a string
being constructed in a single pass.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Reported-by: Ranier Vilela <ranier.vf@gmail.com>
Reviewed-by: Yang Yuanzhuo <1197620467@qq.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Discussion: https://postgr.es/m/CAEudQAq2wyXZRdsh+wVHcOrungPU+_aQeQU12wbcgrmE0bQovA@mail.gmail.com
This commit is contained in:
Álvaro Herrera
2026-03-10 16:00:19 +01:00
parent 59bae23435
commit a198c26ded
+7 -10
View File
@@ -1833,7 +1833,6 @@ dropDBs(PGconn *conn)
for (i = 0; i < PQntuples(res); i++)
{
char *dbname = PQgetvalue(res, i, 0);
PQExpBuffer delQry = createPQExpBuffer();
/*
* Skip "postgres" and "template1"; dumpDatabases() will deal with
@@ -1846,15 +1845,14 @@ dropDBs(PGconn *conn)
{
if (archDumpFormat == archNull)
{
appendPQExpBuffer(delQry, "DROP DATABASE %s%s;\n",
if_exists ? "IF EXISTS " : "",
fmtId(dbname));
fprintf(OPF, "%s", delQry->data);
fprintf(OPF, "DROP DATABASE %s%s;\n",
if_exists ? "IF EXISTS " : "",
fmtId(dbname));
}
else
{
appendPQExpBuffer(delQry, "DROP DATABASE IF EXISTS %s;\n",
fmtId(dbname));
char *stmt = psprintf("DROP DATABASE IF EXISTS %s;\n",
fmtId(dbname));
ArchiveEntry(fout,
nilCatalogId, /* catalog ID */
@@ -1862,10 +1860,9 @@ dropDBs(PGconn *conn)
ARCHIVE_OPTS(.tag = psprintf("DATABASE %s", fmtId(dbname)),
.description = "DROP_GLOBAL",
.section = SECTION_PRE_DATA,
.createStmt = delQry->data));
.createStmt = stmt));
pg_free(stmt);
}
destroyPQExpBuffer(delQry);
}
}