Fixup some appendStringInfo and appendPQExpBuffer calls
authorDavid Rowley <[email protected]>
Thu, 15 Oct 2020 07:35:17 +0000 (20:35 +1300)
committerDavid Rowley <[email protected]>
Thu, 15 Oct 2020 07:35:17 +0000 (20:35 +1300)
A number of places were using appendStringInfo() when they could have been
using appendStringInfoString() instead.  While there's no functionality
change there, it's just more efficient to use appendStringInfoString()
when no formatting is required.  Likewise for some
appendStringInfoString() calls which were just appending a single char.
We can just use appendStringInfoChar() for that.

Additionally, many places were using appendPQExpBuffer() when they could
have used appendPQExpBufferStr(). Change those too.

Patch by Zhijie Hou, but further searching by me found significantly more
places that deserved the same treatment.

Author: Zhijie Hou, David Rowley
Discussion: https://postgr.es/m/cb172cf4361e4c7ba7167429070979d4@G08CNEXMBPEKD05.g08.fujitsu.local

15 files changed:
contrib/postgres_fdw/postgres_fdw.c
contrib/test_decoding/test_decoding.c
src/backend/access/rmgrdesc/dbasedesc.c
src/backend/commands/explain.c
src/backend/replication/backup_manifest.c
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
src/backend/replication/logical/tablesync.c
src/backend/utils/adt/jsonpath.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ruleutils.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_upgrade/version.c
src/bin/psql/describe.c
src/bin/scripts/reindexdb.c
src/pl/plpython/plpy_elog.c

index 78facb8ebfa49728a996cf2737560da9b5c621f0..9c5aaacc515667bc0a687c9e48a47456faad6329 100644 (file)
@@ -2591,8 +2591,8 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
                                     quote_identifier(relname));
                }
                else
-                   appendStringInfo(relations, "%s",
-                                    quote_identifier(relname));
+                   appendStringInfoString(relations,
+                                          quote_identifier(relname));
                refname = (char *) list_nth(es->rtable_names, rti - 1);
                if (refname == NULL)
                    refname = rte->eref->aliasname;
index e60ab34a5a7cd6bfe8d1867c250d61b9c92d69d9..8e33614f14424a101611baea09305f879a6f077c 100644 (file)
@@ -606,7 +606,7 @@ pg_output_stream_start(LogicalDecodingContext *ctx, TestDecodingData *data, Reor
    if (data->include_xids)
        appendStringInfo(ctx->out, "opening a streamed block for transaction TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "opening a streamed block for transaction");
+       appendStringInfoString(ctx->out, "opening a streamed block for transaction");
    OutputPluginWrite(ctx, last_write);
 }
 
@@ -623,7 +623,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
    if (data->include_xids)
        appendStringInfo(ctx->out, "closing a streamed block for transaction TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "closing a streamed block for transaction");
+       appendStringInfoString(ctx->out, "closing a streamed block for transaction");
    OutputPluginWrite(ctx, true);
 }
 
@@ -641,7 +641,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
    if (data->include_xids)
        appendStringInfo(ctx->out, "aborting streamed (sub)transaction TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "aborting streamed (sub)transaction");
+       appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
    OutputPluginWrite(ctx, true);
 }
 
@@ -660,7 +660,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
    if (data->include_xids)
        appendStringInfo(ctx->out, "committing streamed transaction TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "committing streamed transaction");
+       appendStringInfoString(ctx->out, "committing streamed transaction");
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
@@ -693,7 +693,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
    if (data->include_xids)
        appendStringInfo(ctx->out, "streaming change for TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "streaming change for transaction");
+       appendStringInfoString(ctx->out, "streaming change for transaction");
    OutputPluginWrite(ctx, true);
 }
 
@@ -745,6 +745,6 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
    if (data->include_xids)
        appendStringInfo(ctx->out, "streaming truncate for TXN %u", txn->xid);
    else
-       appendStringInfo(ctx->out, "streaming truncate for transaction");
+       appendStringInfoString(ctx->out, "streaming truncate for transaction");
    OutputPluginWrite(ctx, true);
 }
index d82484b9db400a351a09849f8c5953f7b555c742..47580feaeae41a6523178ab0b8c6a3b9bf92c2a1 100644 (file)
@@ -37,7 +37,7 @@ dbase_desc(StringInfo buf, XLogReaderState *record)
        xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) rec;
        int         i;
 
-       appendStringInfo(buf, "dir");
+       appendStringInfoString(buf, "dir");
        for (i = 0; i < xlrec->ntablespaces; i++)
            appendStringInfo(buf, " %u/%u",
                             xlrec->tablespace_ids[i], xlrec->db_id);
index c8e292adfa63e797cd52fc6a4844665209751580..41317f18374382595b8b125640c90b8dd4fe80bc 100644 (file)
@@ -2768,14 +2768,14 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
                         groupInfo->groupCount);
        /* plural/singular based on methodNames size */
        if (list_length(methodNames) > 1)
-           appendStringInfo(es->str, "s: ");
+           appendStringInfoString(es->str, "s: ");
        else
-           appendStringInfo(es->str, ": ");
+           appendStringInfoString(es->str, ": ");
        foreach(methodCell, methodNames)
        {
-           appendStringInfo(es->str, "%s", (char *) methodCell->ptr_value);
+           appendStringInfoString(es->str, (char *) methodCell->ptr_value);
            if (foreach_current_index(methodCell) < list_length(methodNames) - 1)
-               appendStringInfo(es->str, ", ");
+               appendStringInfoString(es->str, ", ");
        }
 
        if (groupInfo->maxMemorySpaceUsed > 0)
@@ -2882,11 +2882,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
        if (prefixsortGroupInfo->groupCount > 0)
        {
            if (es->format == EXPLAIN_FORMAT_TEXT)
-               appendStringInfo(es->str, "\n");
+               appendStringInfoChar(es->str, '\n');
            show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
        }
        if (es->format == EXPLAIN_FORMAT_TEXT)
-           appendStringInfo(es->str, "\n");
+           appendStringInfoChar(es->str, '\n');
    }
 
    if (incrsortstate->shared_info != NULL)
@@ -2925,11 +2925,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
            if (prefixsortGroupInfo->groupCount > 0)
            {
                if (es->format == EXPLAIN_FORMAT_TEXT)
-                   appendStringInfo(es->str, "\n");
+                   appendStringInfoChar(es->str, '\n');
                show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
            }
            if (es->format == EXPLAIN_FORMAT_TEXT)
-               appendStringInfo(es->str, "\n");
+               appendStringInfoChar(es->str, '\n');
 
            if (es->workers_state)
                ExplainCloseWorker(n, es);
index a43c793e2892ad1523ce42c7c24ddea34dd48436..556e6b50408524ea45b0e584e586b6eaa736b064 100644 (file)
@@ -112,7 +112,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
    initStringInfo(&buf);
    if (manifest->first_file)
    {
-       appendStringInfoString(&buf, "\n");
+       appendStringInfoChar(&buf, '\n');
        manifest->first_file = false;
    }
    else
@@ -152,7 +152,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
    enlargeStringInfo(&buf, 128);
    buf.len += pg_strftime(&buf.data[buf.len], 128, "%Y-%m-%d %H:%M:%S %Z",
                           pg_gmtime(&mtime));
-   appendStringInfoString(&buf, "\"");
+   appendStringInfoChar(&buf, '"');
 
    /* Add checksum information. */
    if (checksum_ctx->type != CHECKSUM_TYPE_NONE)
@@ -168,7 +168,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
        enlargeStringInfo(&buf, 2 * checksumlen);
        buf.len += hex_encode((char *) checksumbuf, checksumlen,
                              &buf.data[buf.len]);
-       appendStringInfoString(&buf, "\"");
+       appendStringInfoChar(&buf, '"');
    }
 
    /* Close out the object. */
index ad574099ff7006d707126737c70537b68a4b67e3..24f8b3e42ecee8b4414c8480bfd5be7de2270f36 100644 (file)
@@ -427,7 +427,7 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
 
        if (options->proto.logical.streaming &&
            PQserverVersion(conn->streamConn) >= 140000)
-           appendStringInfo(&cmd, ", streaming 'on'");
+           appendStringInfoString(&cmd, ", streaming 'on'");
 
        pubnames = options->proto.logical.publication_names;
        pubnames_str = stringlist_to_identifierstr(conn->streamConn, pubnames);
index c27d97058955a9c6023afb71b8017648cd740ea3..843c9285d59d63bada0663e77e7b3d89857c1ed8 100644 (file)
@@ -774,7 +774,7 @@ copy_table(Relation rel)
         * For non-tables, we need to do COPY (SELECT ...), but we can't just
         * do SELECT * because we need to not copy generated columns.
         */
-       appendStringInfo(&cmd, "COPY (SELECT ");
+       appendStringInfoString(&cmd, "COPY (SELECT ");
        for (int i = 0; i < lrel.natts; i++)
        {
            appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));
index 3c0dc38a7f84e456476dee71ab41f1c8765b65dd..31d9d92d14ed536b82ad5eb587e49da0a5a827e8 100644 (file)
@@ -660,7 +660,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
            else if (v->content.anybounds.first == v->content.anybounds.last)
            {
                if (v->content.anybounds.first == PG_UINT32_MAX)
-                   appendStringInfo(buf, "**{last}");
+                   appendStringInfoString(buf, "**{last}");
                else
                    appendStringInfo(buf, "**{%u}",
                                     v->content.anybounds.first);
index 06cf16d9d71649bd8adb20410a7e5134f5d5a2a6..7e2b2e3dd64681d275fcf16ca4d09938e6dfa911 100644 (file)
@@ -1663,7 +1663,7 @@ RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
        appendStringInfo(&querybuf, ") WHERE %s AND (",
                         constraintDef);
    else
-       appendStringInfo(&querybuf, ") WHERE (");
+       appendStringInfoString(&querybuf, ") WHERE (");
 
    sep = "";
    for (i = 0; i < riinfo->nkeys; i++)
index 62023c20b21e30f1612a1734128b74b8252b6acc..6c656586e857803b56958393a5a550196899bc33 100644 (file)
@@ -5250,7 +5250,7 @@ get_select_query_def(Query *query, deparse_context *context,
            appendContextKeyword(context, " FETCH FIRST ",
                                 -PRETTYINDENT_STD, PRETTYINDENT_STD, 0);
            get_rule_expr(query->limitCount, context, false);
-           appendStringInfo(buf, " ROWS WITH TIES");
+           appendStringInfoString(buf, " ROWS WITH TIES");
        }
        else
        {
@@ -11362,7 +11362,7 @@ get_range_partbound_string(List *bound_datums)
    memset(&context, 0, sizeof(deparse_context));
    context.buf = buf;
 
-   appendStringInfoString(buf, "(");
+   appendStringInfoChar(buf, '(');
    sep = "";
    foreach(cell, bound_datums)
    {
index 88bbbd9a9e1c41ae87d60075c4328e9c90882a1b..ff45e3fb8c3797179f71ba377dddea57af9e289b 100644 (file)
@@ -1375,8 +1375,8 @@ expand_foreign_server_name_patterns(Archive *fout,
 
    for (cell = patterns->head; cell; cell = cell->next)
    {
-       appendPQExpBuffer(query,
-                         "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
+       appendPQExpBufferStr(query,
+                            "SELECT oid FROM pg_catalog.pg_foreign_server s\n");
        processSQLNamePattern(GetConnection(fout), query, cell->val, false,
                              false, NULL, "s.srvname", NULL, NULL);
 
@@ -4250,23 +4250,19 @@ getSubscriptions(Archive *fout)
                      username_subquery);
 
    if (fout->remoteVersion >= 140000)
-       appendPQExpBuffer(query,
-                         " s.subbinary,\n");
+       appendPQExpBufferStr(query, " s.subbinary,\n");
    else
-       appendPQExpBuffer(query,
-                         " false AS subbinary,\n");
+       appendPQExpBufferStr(query, " false AS subbinary,\n");
 
    if (fout->remoteVersion >= 140000)
-       appendPQExpBuffer(query,
-                         " s.substream\n");
+       appendPQExpBufferStr(query, " s.substream\n");
    else
-       appendPQExpBuffer(query,
-                         " false AS substream\n");
+       appendPQExpBufferStr(query, " false AS substream\n");
 
-   appendPQExpBuffer(query,
-                     "FROM pg_subscription s\n"
-                     "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
-                     "                   WHERE datname = current_database())");
+   appendPQExpBufferStr(query,
+                        "FROM pg_subscription s\n"
+                        "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
+                        "                   WHERE datname = current_database())");
 
    res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
@@ -4376,10 +4372,10 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
        appendPQExpBufferStr(query, "NONE");
 
    if (strcmp(subinfo->subbinary, "t") == 0)
-       appendPQExpBuffer(query, ", binary = true");
+       appendPQExpBufferStr(query, ", binary = true");
 
    if (strcmp(subinfo->substream, "f") != 0)
-       appendPQExpBuffer(query, ", streaming = on");
+       appendPQExpBufferStr(query, ", streaming = on");
 
    if (strcmp(subinfo->subsynccommit, "off") != 0)
        appendPQExpBuffer(query, ", synchronous_commit = %s", fmtId(subinfo->subsynccommit));
@@ -11845,26 +11841,26 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
    asPart = createPQExpBuffer();
 
    /* Fetch function-specific details */
-   appendPQExpBuffer(query,
-                     "SELECT\n"
-                     "proretset,\n"
-                     "prosrc,\n"
-                     "probin,\n"
-                     "provolatile,\n"
-                     "proisstrict,\n"
-                     "prosecdef,\n"
-                     "(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname,\n");
+   appendPQExpBufferStr(query,
+                        "SELECT\n"
+                        "proretset,\n"
+                        "prosrc,\n"
+                        "probin,\n"
+                        "provolatile,\n"
+                        "proisstrict,\n"
+                        "prosecdef,\n"
+                        "(SELECT lanname FROM pg_catalog.pg_language WHERE oid = prolang) AS lanname,\n");
 
    if (fout->remoteVersion >= 80300)
-       appendPQExpBuffer(query,
-                         "proconfig,\n"
-                         "procost,\n"
-                         "prorows,\n");
+       appendPQExpBufferStr(query,
+                            "proconfig,\n"
+                            "procost,\n"
+                            "prorows,\n");
    else
-       appendPQExpBuffer(query,
-                         "null AS proconfig,\n"
-                         "0 AS procost,\n"
-                         "0 AS prorows,\n");
+       appendPQExpBufferStr(query,
+                            "null AS proconfig,\n"
+                            "0 AS procost,\n"
+                            "0 AS prorows,\n");
 
    if (fout->remoteVersion >= 80400)
    {
@@ -11872,56 +11868,56 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
         * In 8.4 and up we rely on pg_get_function_arguments and
         * pg_get_function_result instead of examining proallargtypes etc.
         */
-       appendPQExpBuffer(query,
-                         "pg_catalog.pg_get_function_arguments(oid) AS funcargs,\n"
-                         "pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs,\n"
-                         "pg_catalog.pg_get_function_result(oid) AS funcresult,\n");
+       appendPQExpBufferStr(query,
+                            "pg_catalog.pg_get_function_arguments(oid) AS funcargs,\n"
+                            "pg_catalog.pg_get_function_identity_arguments(oid) AS funciargs,\n"
+                            "pg_catalog.pg_get_function_result(oid) AS funcresult,\n");
    }
    else if (fout->remoteVersion >= 80100)
-       appendPQExpBuffer(query,
-                         "proallargtypes,\n"
-                         "proargmodes,\n"
-                         "proargnames,\n");
+       appendPQExpBufferStr(query,
+                            "proallargtypes,\n"
+                            "proargmodes,\n"
+                            "proargnames,\n");
    else
-       appendPQExpBuffer(query,
-                         "null AS proallargtypes,\n"
-                         "null AS proargmodes,\n"
-                         "proargnames,\n");
+       appendPQExpBufferStr(query,
+                            "null AS proallargtypes,\n"
+                            "null AS proargmodes,\n"
+                            "proargnames,\n");
 
    if (fout->remoteVersion >= 90200)
-       appendPQExpBuffer(query,
-                         "proleakproof,\n");
+       appendPQExpBufferStr(query,
+                            "proleakproof,\n");
    else
-       appendPQExpBuffer(query,
-                         "false AS proleakproof,\n");
+       appendPQExpBufferStr(query,
+                            "false AS proleakproof,\n");
 
    if (fout->remoteVersion >= 90500)
-       appendPQExpBuffer(query,
-                         "array_to_string(protrftypes, ' ') AS protrftypes,\n");
+       appendPQExpBufferStr(query,
+                            "array_to_string(protrftypes, ' ') AS protrftypes,\n");
 
    if (fout->remoteVersion >= 90600)
-       appendPQExpBuffer(query,
-                         "proparallel,\n");
+       appendPQExpBufferStr(query,
+                            "proparallel,\n");
    else
-       appendPQExpBuffer(query,
-                         "'u' AS proparallel,\n");
+       appendPQExpBufferStr(query,
+                            "'u' AS proparallel,\n");
 
    if (fout->remoteVersion >= 110000)
-       appendPQExpBuffer(query,
-                         "prokind,\n");
+       appendPQExpBufferStr(query,
+                            "prokind,\n");
    else if (fout->remoteVersion >= 80400)
-       appendPQExpBuffer(query,
-                         "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
+       appendPQExpBufferStr(query,
+                            "CASE WHEN proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
    else
-       appendPQExpBuffer(query,
-                         "'f' AS prokind,\n");
+       appendPQExpBufferStr(query,
+                            "'f' AS prokind,\n");
 
    if (fout->remoteVersion >= 120000)
-       appendPQExpBuffer(query,
-                         "prosupport\n");
+       appendPQExpBufferStr(query,
+                            "prosupport\n");
    else
-       appendPQExpBuffer(query,
-                         "'-' AS prosupport\n");
+       appendPQExpBufferStr(query,
+                            "'-' AS prosupport\n");
 
    appendPQExpBuffer(query,
                      "FROM pg_catalog.pg_proc "
@@ -13891,71 +13887,71 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
    details = createPQExpBuffer();
 
    /* Get aggregate-specific details */
-   appendPQExpBuffer(query,
-                     "SELECT\n"
-                     "aggtransfn,\n"
-                     "aggfinalfn,\n"
-                     "aggtranstype::pg_catalog.regtype,\n"
-                     "agginitval,\n");
+   appendPQExpBufferStr(query,
+                        "SELECT\n"
+                        "aggtransfn,\n"
+                        "aggfinalfn,\n"
+                        "aggtranstype::pg_catalog.regtype,\n"
+                        "agginitval,\n");
 
    if (fout->remoteVersion >= 80100)
-       appendPQExpBuffer(query,
-                         "aggsortop,\n");
+       appendPQExpBufferStr(query,
+                            "aggsortop,\n");
    else
-       appendPQExpBuffer(query,
-                         "0 AS aggsortop,\n");
+       appendPQExpBufferStr(query,
+                            "0 AS aggsortop,\n");
 
    if (fout->remoteVersion >= 80400)
-       appendPQExpBuffer(query,
-                         "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
-                         "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
+       appendPQExpBufferStr(query,
+                            "pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
+                            "pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
 
    if (fout->remoteVersion >= 90400)
-       appendPQExpBuffer(query,
-                         "aggkind,\n"
-                         "aggmtransfn,\n"
-                         "aggminvtransfn,\n"
-                         "aggmfinalfn,\n"
-                         "aggmtranstype::pg_catalog.regtype,\n"
-                         "aggfinalextra,\n"
-                         "aggmfinalextra,\n"
-                         "aggtransspace,\n"
-                         "aggmtransspace,\n"
-                         "aggminitval,\n");
+       appendPQExpBufferStr(query,
+                            "aggkind,\n"
+                            "aggmtransfn,\n"
+                            "aggminvtransfn,\n"
+                            "aggmfinalfn,\n"
+                            "aggmtranstype::pg_catalog.regtype,\n"
+                            "aggfinalextra,\n"
+                            "aggmfinalextra,\n"
+                            "aggtransspace,\n"
+                            "aggmtransspace,\n"
+                            "aggminitval,\n");
    else
-       appendPQExpBuffer(query,
-                         "'n' AS aggkind,\n"
-                         "'-' AS aggmtransfn,\n"
-                         "'-' AS aggminvtransfn,\n"
-                         "'-' AS aggmfinalfn,\n"
-                         "0 AS aggmtranstype,\n"
-                         "false AS aggfinalextra,\n"
-                         "false AS aggmfinalextra,\n"
-                         "0 AS aggtransspace,\n"
-                         "0 AS aggmtransspace,\n"
-                         "NULL AS aggminitval,\n");
+       appendPQExpBufferStr(query,
+                            "'n' AS aggkind,\n"
+                            "'-' AS aggmtransfn,\n"
+                            "'-' AS aggminvtransfn,\n"
+                            "'-' AS aggmfinalfn,\n"
+                            "0 AS aggmtranstype,\n"
+                            "false AS aggfinalextra,\n"
+                            "false AS aggmfinalextra,\n"
+                            "0 AS aggtransspace,\n"
+                            "0 AS aggmtransspace,\n"
+                            "NULL AS aggminitval,\n");
 
    if (fout->remoteVersion >= 90600)
-       appendPQExpBuffer(query,
-                         "aggcombinefn,\n"
-                         "aggserialfn,\n"
-                         "aggdeserialfn,\n"
-                         "proparallel,\n");
+       appendPQExpBufferStr(query,
+                            "aggcombinefn,\n"
+                            "aggserialfn,\n"
+                            "aggdeserialfn,\n"
+                            "proparallel,\n");
    else
-       appendPQExpBuffer(query,
-                         "'-' AS aggcombinefn,\n"
-                         "'-' AS aggserialfn,\n"
-                         "'-' AS aggdeserialfn,\n"
-                         "'u' AS proparallel,\n");
+       appendPQExpBufferStr(query,
+                            "'-' AS aggcombinefn,\n"
+                            "'-' AS aggserialfn,\n"
+                            "'-' AS aggdeserialfn,\n"
+                            "'u' AS proparallel,\n");
 
    if (fout->remoteVersion >= 110000)
-       appendPQExpBuffer(query,
-                         "aggfinalmodify,\n"
-                         "aggmfinalmodify\n");
+       appendPQExpBufferStr(query,
+                            "aggfinalmodify,\n"
+                            "aggmfinalmodify\n");
    else
-       appendPQExpBuffer(query,
-                         "'0' AS aggfinalmodify,\n"
-                         "'0' AS aggmfinalmodify\n");
+       appendPQExpBufferStr(query,
+                            "'0' AS aggfinalmodify,\n"
+                            "'0' AS aggmfinalmodify\n");
 
    appendPQExpBuffer(query,
                      "FROM pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
index 4e5d27f76eb2f4d3e037d44559f4266ca8946975..db1934124ee350229dfe26220026e41200a4acf5 100644 (file)
@@ -158,33 +158,33 @@ check_for_data_type_usage(ClusterInfo *cluster, const char *typename,
 
        /* Ranges were introduced in 9.2 */
        if (GET_MAJOR_VERSION(cluster->major_version) >= 902)
-           appendPQExpBuffer(&querybuf,
-                             "         UNION ALL "
+           appendPQExpBufferStr(&querybuf,
+                                "          UNION ALL "
            /* ranges containing any type selected so far */
-                             "         SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x "
-                             "         WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid");
+                                "          SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x "
+                                "          WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid");
 
-       appendPQExpBuffer(&querybuf,
-                         " ) foo "
-                         ") "
+       appendPQExpBufferStr(&querybuf,
+                            "  ) foo "
+                            ") "
        /* now look for stored columns of any such type */
-                         "SELECT n.nspname, c.relname, a.attname "
-                         "FROM pg_catalog.pg_class c, "
-                         "     pg_catalog.pg_namespace n, "
-                         "     pg_catalog.pg_attribute a "
-                         "WHERE    c.oid = a.attrelid AND "
-                         "     NOT a.attisdropped AND "
-                         "     a.atttypid IN (SELECT oid FROM oids) AND "
-                         "     c.relkind IN ("
-                         CppAsString2(RELKIND_RELATION) ", "
-                         CppAsString2(RELKIND_MATVIEW) ", "
-                         CppAsString2(RELKIND_INDEX) ") AND "
-                         "     c.relnamespace = n.oid AND "
+                            "SELECT n.nspname, c.relname, a.attname "
+                            "FROM  pg_catalog.pg_class c, "
+                            "      pg_catalog.pg_namespace n, "
+                            "      pg_catalog.pg_attribute a "
+                            "WHERE c.oid = a.attrelid AND "
+                            "      NOT a.attisdropped AND "
+                            "      a.atttypid IN (SELECT oid FROM oids) AND "
+                            "      c.relkind IN ("
+                            CppAsString2(RELKIND_RELATION) ", "
+                            CppAsString2(RELKIND_MATVIEW) ", "
+                            CppAsString2(RELKIND_INDEX) ") AND "
+                            "      c.relnamespace = n.oid AND "
        /* exclude possible orphaned temp tables */
-                         "     n.nspname !~ '^pg_temp_' AND "
-                         "     n.nspname !~ '^pg_toast_temp_' AND "
+                            "      n.nspname !~ '^pg_temp_' AND "
+                            "      n.nspname !~ '^pg_toast_temp_' AND "
        /* exclude system catalogs, too */
-                         "     n.nspname NOT IN ('pg_catalog', 'information_schema')");
+                            "      n.nspname NOT IN ('pg_catalog', 'information_schema')");
 
        res = executeQueryOrDie(conn, "%s", querybuf.data);
 
index 58de433fd302f64ff573b645ad1312c3f29c5196..6bb0316bd98bb7b231c381da6dab310403618e79 100644 (file)
@@ -6137,17 +6137,16 @@ listOperatorClasses(const char *access_method_pattern,
                          " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
                          gettext_noop("Operator family"),
                          gettext_noop("Owner"));
-   appendPQExpBuffer(&buf,
-                     "\nFROM pg_catalog.pg_opclass c\n"
-                     "  LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
-                     "  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
-                     "  LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
-                     "  LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
-       );
+   appendPQExpBufferStr(&buf,
+                        "\nFROM pg_catalog.pg_opclass c\n"
+                        "  LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
+                        "  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
+                        "  LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
+                        "  LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
    if (verbose)
-       appendPQExpBuffer(&buf,
-                         "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
-                         "  LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
+       appendPQExpBufferStr(&buf,
+                            "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
+                            "  LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
 
    if (access_method_pattern)
        have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
@@ -6216,11 +6215,10 @@ listOperatorFamilies(const char *access_method_pattern,
        appendPQExpBuffer(&buf,
                          ",\n  pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
                          gettext_noop("Owner"));
-   appendPQExpBuffer(&buf,
-                     "\nFROM pg_catalog.pg_opfamily f\n"
-                     "  LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
-                     "  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n"
-       );
+   appendPQExpBufferStr(&buf,
+                        "\nFROM pg_catalog.pg_opfamily f\n"
+                        "  LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
+                        "  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
 
    if (access_method_pattern)
        have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
@@ -6240,7 +6238,7 @@ listOperatorFamilies(const char *access_method_pattern,
                              "tn.nspname", "t.typname",
                              "pg_catalog.format_type(t.oid, NULL)",
                              "pg_catalog.pg_type_is_visible(t.oid)");
-       appendPQExpBuffer(&buf, "  )\n");
+       appendPQExpBufferStr(&buf, "  )\n");
    }
 
    appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
@@ -6307,14 +6305,14 @@ listOpFamilyOperators(const char *access_method_pattern,
        appendPQExpBuffer(&buf,
                          ", ofs.opfname AS \"%s\"\n",
                          gettext_noop("Sort opfamily"));
-   appendPQExpBuffer(&buf,
-                     "FROM pg_catalog.pg_amop o\n"
-                     "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
-                     "  LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
-                     "  LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
+   appendPQExpBufferStr(&buf,
+                        "FROM pg_catalog.pg_amop o\n"
+                        "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
+                        "  LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
+                        "  LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
    if (verbose)
-       appendPQExpBuffer(&buf,
-                         "  LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
+       appendPQExpBufferStr(&buf,
+                            "  LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n");
 
    if (access_method_pattern)
        have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
@@ -6393,12 +6391,12 @@ listOpFamilyFunctions(const char *access_method_pattern,
                          ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
                          gettext_noop("Function"));
 
-   appendPQExpBuffer(&buf,
-                     "FROM pg_catalog.pg_amproc ap\n"
-                     "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
-                     "  LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
-                     "  LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
-                     "  LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
+   appendPQExpBufferStr(&buf,
+                        "FROM pg_catalog.pg_amproc ap\n"
+                        "  LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
+                        "  LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
+                        "  LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
+                        "  LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
 
    if (access_method_pattern)
        have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
index 40dcbc928332416f0fb7e11431be6612ecb55271..1efb53110efac201ab4eb08a6bcdc7f82490875e 100644 (file)
@@ -614,16 +614,16 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
    {
        case REINDEX_DATABASE:
            Assert(user_list == NULL);
-           appendPQExpBuffer(&catalog_query,
-                             "SELECT c.relname, ns.nspname\n"
-                             " FROM pg_catalog.pg_class c\n"
-                             " JOIN pg_catalog.pg_namespace ns"
-                             " ON c.relnamespace = ns.oid\n"
-                             " WHERE ns.nspname != 'pg_catalog'\n"
-                             "   AND c.relkind IN ("
-                             CppAsString2(RELKIND_RELATION) ", "
-                             CppAsString2(RELKIND_MATVIEW) ")\n"
-                             " ORDER BY c.relpages DESC;");
+           appendPQExpBufferStr(&catalog_query,
+                                "SELECT c.relname, ns.nspname\n"
+                                " FROM pg_catalog.pg_class c\n"
+                                " JOIN pg_catalog.pg_namespace ns"
+                                " ON c.relnamespace = ns.oid\n"
+                                " WHERE ns.nspname != 'pg_catalog'\n"
+                                "   AND c.relkind IN ("
+                                CppAsString2(RELKIND_RELATION) ", "
+                                CppAsString2(RELKIND_MATVIEW) ")\n"
+                                " ORDER BY c.relpages DESC;");
            break;
 
        case REINDEX_SCHEMA:
@@ -637,30 +637,30 @@ get_parallel_object_list(PGconn *conn, ReindexType type,
                 * All the tables from all the listed schemas are grabbed at
                 * once.
                 */
-               appendPQExpBuffer(&catalog_query,
-                                 "SELECT c.relname, ns.nspname\n"
-                                 " FROM pg_catalog.pg_class c\n"
-                                 " JOIN pg_catalog.pg_namespace ns"
-                                 " ON c.relnamespace = ns.oid\n"
-                                 " WHERE c.relkind IN ("
-                                 CppAsString2(RELKIND_RELATION) ", "
-                                 CppAsString2(RELKIND_MATVIEW) ")\n"
-                                 " AND ns.nspname IN (");
+               appendPQExpBufferStr(&catalog_query,
+                                    "SELECT c.relname, ns.nspname\n"
+                                    " FROM pg_catalog.pg_class c\n"
+                                    " JOIN pg_catalog.pg_namespace ns"
+                                    " ON c.relnamespace = ns.oid\n"
+                                    " WHERE c.relkind IN ("
+                                    CppAsString2(RELKIND_RELATION) ", "
+                                    CppAsString2(RELKIND_MATVIEW) ")\n"
+                                    " AND ns.nspname IN (");
 
                for (cell = user_list->head; cell; cell = cell->next)
                {
                    const char *nspname = cell->val;
 
                    if (nsp_listed)
-                       appendPQExpBuffer(&catalog_query, ", ");
+                       appendPQExpBufferStr(&catalog_query, ", ");
                    else
                        nsp_listed = true;
 
                    appendStringLiteralConn(&catalog_query, nspname, conn);
                }
 
-               appendPQExpBuffer(&catalog_query, ")\n"
-                                 " ORDER BY c.relpages DESC;");
+               appendPQExpBufferStr(&catalog_query, ")\n"
+                                    " ORDER BY c.relpages DESC;");
            }
            break;
 
index ae0b97c85d3f2e7f70c566edd64151d44bf3f047..224b8836fba90011a0f69a73efafb383c1817c15 100644 (file)
@@ -216,7 +216,7 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
    else if (strcmp(e_module_s, "builtins") == 0
             || strcmp(e_module_s, "__main__") == 0
             || strcmp(e_module_s, "exceptions") == 0)
-       appendStringInfo(&xstr, "%s", e_type_s);
+       appendStringInfoString(&xstr, e_type_s);
    else
        appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
    appendStringInfo(&xstr, ": %s", vstr);