static List *textarray_to_stringlist(ArrayType *textarray);
+/*
+ * Add a comma-separated list of publication names to the 'dest' string.
+ */
+void
+GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal)
+{
+ ListCell *lc;
+ bool first = true;
+
+ Assert(publications != NIL);
+
+ foreach(lc, publications)
+ {
+ char *pubname = strVal(lfirst(lc));
+
+ if (first)
+ first = false;
+ else
+ appendStringInfoString(dest, ", ");
+
+ if (quote_literal)
+ appendStringInfoString(dest, quote_literal_cstr(pubname));
+ else
+ {
+ appendStringInfoChar(dest, '"');
+ appendStringInfoString(dest, pubname);
+ appendStringInfoChar(dest, '"');
+ }
+ }
+}
+
/*
* Fetch the subscription from the syscache.
*/
}
}
-/*
- * Add publication names from the list to a string.
- */
-static void
-get_publications_str(List *publications, StringInfo dest, bool quote_literal)
-{
- ListCell *lc;
- bool first = true;
-
- Assert(publications != NIL);
-
- foreach(lc, publications)
- {
- char *pubname = strVal(lfirst(lc));
-
- if (first)
- first = false;
- else
- appendStringInfoString(dest, ", ");
-
- if (quote_literal)
- appendStringInfoString(dest, quote_literal_cstr(pubname));
- else
- {
- appendStringInfoChar(dest, '"');
- appendStringInfoString(dest, pubname);
- appendStringInfoChar(dest, '"');
- }
- }
-}
-
/*
* Check that the specified publications are present on the publisher.
*/
appendStringInfoString(cmd, "SELECT t.pubname FROM\n"
" pg_catalog.pg_publication t WHERE\n"
" t.pubname IN (");
- get_publications_str(publications, cmd, true);
+ GetPublicationsStr(publications, cmd, true);
appendStringInfoChar(cmd, ')');
res = walrcv_exec(wrconn, cmd->data, 1, tableRow);
/* Prepare the list of non-existent publication(s) for error message. */
StringInfo pubnames = makeStringInfo();
- get_publications_str(publicationsCopy, pubnames, false);
+ GetPublicationsStr(publicationsCopy, pubnames, false);
ereport(WARNING,
errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg_plural("publication %s does not exist on the publisher",
" JOIN pg_subscription_rel PS ON (GPT.relid = PS.srrelid),\n"
" pg_class C JOIN pg_namespace N ON (N.oid = C.relnamespace)\n"
"WHERE C.oid = GPT.relid AND P.pubname IN (");
- get_publications_str(publications, &cmd, true);
+ GetPublicationsStr(publications, &cmd, true);
appendStringInfoString(&cmd, ")\n");
/*
StringInfo pubnames = makeStringInfo();
/* Prepare the list of publication(s) for warning message. */
- get_publications_str(publist, pubnames, false);
+ GetPublicationsStr(publist, pubnames, false);
ereport(WARNING,
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("subscription \"%s\" requested copy_data with origin = NONE but might copy data that had a different origin",
List *tablelist = NIL;
int server_version = walrcv_server_version(wrconn);
bool check_columnlist = (server_version >= 150000);
+ StringInfo pub_names = makeStringInfo();
initStringInfo(&cmd);
+ /* Build the pub_names comma-separated string. */
+ GetPublicationsStr(publications, pub_names, true);
+
/* Get the list of tables from the publisher. */
if (server_version >= 160000)
{
- StringInfoData pub_names;
-
tableRow[2] = INT2VECTOROID;
- initStringInfo(&pub_names);
- get_publications_str(publications, &pub_names, true);
/*
* From version 16, we allowed passing multiple publications to the
" FROM pg_publication\n"
" WHERE pubname IN ( %s )) AS gpt\n"
" ON gpt.relid = c.oid\n",
- pub_names.data);
-
- pfree(pub_names.data);
+ pub_names->data);
}
else
{
if (check_columnlist)
appendStringInfoString(&cmd, ", t.attnames\n");
- appendStringInfoString(&cmd, "FROM pg_catalog.pg_publication_tables t\n"
- " WHERE t.pubname IN (");
- get_publications_str(publications, &cmd, true);
- appendStringInfoChar(&cmd, ')');
+ appendStringInfo(&cmd, "FROM pg_catalog.pg_publication_tables t\n"
+ " WHERE t.pubname IN ( %s )",
+ pub_names->data);
}
+ destroyStringInfo(pub_names);
+
res = walrcv_exec(wrconn, cmd.data, check_columnlist ? 3 : 2, tableRow);
pfree(cmd.data);
Oid qualRow[] = {TEXTOID};
bool isnull;
int natt;
- ListCell *lc;
+ StringInfo pub_names = NULL;
Bitmapset *included_cols = NULL;
lrel->nspname = nspname;
WalRcvExecResult *pubres;
TupleTableSlot *tslot;
Oid attrsRow[] = {INT2VECTOROID};
- StringInfoData pub_names;
- initStringInfo(&pub_names);
- foreach(lc, MySubscription->publications)
- {
- if (foreach_current_index(lc) > 0)
- appendStringInfoString(&pub_names, ", ");
- appendStringInfoString(&pub_names, quote_literal_cstr(strVal(lfirst(lc))));
- }
+ /* Build the pub_names comma-separated string. */
+ pub_names = makeStringInfo();
+ GetPublicationsStr(MySubscription->publications, pub_names, true);
/*
* Fetch info about column lists for the relation (from all the
" WHERE gpt.relid = %u AND c.oid = gpt.relid"
" AND p.pubname IN ( %s )",
lrel->remoteid,
- pub_names.data);
+ pub_names->data);
pubres = walrcv_exec(LogRepWorkerWalRcvConn, cmd.data,
lengthof(attrsRow), attrsRow);
ExecDropSingleTupleTableSlot(tslot);
walrcv_clear_result(pubres);
-
- pfree(pub_names.data);
}
/*
*/
if (walrcv_server_version(LogRepWorkerWalRcvConn) >= 150000)
{
- StringInfoData pub_names;
-
- /* Build the pubname list. */
- initStringInfo(&pub_names);
- foreach_node(String, pubstr, MySubscription->publications)
- {
- char *pubname = strVal(pubstr);
-
- if (foreach_current_index(pubstr) > 0)
- appendStringInfoString(&pub_names, ", ");
-
- appendStringInfoString(&pub_names, quote_literal_cstr(pubname));
- }
+ /* Reuse the already-built pub_names. */
+ Assert(pub_names != NULL);
/* Check for row filters. */
resetStringInfo(&cmd);
" WHERE gpt.relid = %u"
" AND p.pubname IN ( %s )",
lrel->remoteid,
- pub_names.data);
+ pub_names->data);
res = walrcv_exec(LogRepWorkerWalRcvConn, cmd.data, 1, qualRow);
ExecDropSingleTupleTableSlot(slot);
walrcv_clear_result(res);
+ destroyStringInfo(pub_names);
}
pfree(cmd.data);