MCPcopy Create free account
hub / github.com/apache/cloudberry / dumpTableData_copy

Function dumpTableData_copy

src/bin/pg_dump/pg_dump.c:2307–2456  ·  view source on GitHub ↗

* Dump a table's contents for loading using the COPY command * - this routine is called by the Archiver when it wants the table * to be dumped. */

Source from the content-addressed store, hash-verified

2305 * to be dumped.
2306 */
2307static int
2308dumpTableData_copy(Archive *fout, const void *dcontext)
2309{
2310 TableDataInfo *tdinfo = (TableDataInfo *) dcontext;
2311 TableInfo *tbinfo = tdinfo->tdtable;
2312 const char *classname = tbinfo->dobj.name;
2313 PQExpBuffer q = createPQExpBuffer();
2314
2315 /*
2316 * Note: can't use getThreadLocalPQExpBuffer() here, we're calling fmtId
2317 * which uses it already.
2318 */
2319 PQExpBuffer clistBuf = createPQExpBuffer();
2320 PGconn *conn = GetConnection(fout);
2321 PGresult *res;
2322 int ret;
2323 char *copybuf;
2324 const char *column_list;
2325
2326 pg_log_info("dumping contents of table \"%s.%s\"",
2327 tbinfo->dobj.namespace->dobj.name, classname);
2328
2329 /*
2330 * Specify the column list explicitly so that we have no possibility of
2331 * retrieving data in the wrong column order. (The default column
2332 * ordering of COPY will not be what we want in certain corner cases
2333 * involving ADD COLUMN and inheritance.)
2334 */
2335 column_list = fmtCopyColumnList(tbinfo, clistBuf);
2336
2337 /*
2338 * Use COPY (SELECT ...) TO when dumping a foreign table's data, and when
2339 * a filter condition was specified. For other cases a simple COPY
2340 * suffices.
2341 */
2342 if (tdinfo->filtercond || tbinfo->relkind == RELKIND_FOREIGN_TABLE)
2343 {
2344 appendPQExpBufferStr(q, "COPY (SELECT ");
2345 /* klugery to get rid of parens in column list */
2346 if (strlen(column_list) > 2)
2347 {
2348 appendPQExpBufferStr(q, column_list + 1);
2349 q->data[q->len - 1] = ' ';
2350 }
2351 else
2352 appendPQExpBufferStr(q, "* ");
2353
2354 appendPQExpBuffer(q, "FROM %s %s) TO stdout;",
2355 fmtQualifiedDumpable(tbinfo),
2356 tdinfo->filtercond ? tdinfo->filtercond : "");
2357 }
2358 else
2359 {
2360 appendPQExpBuffer(q, "COPY %s %s TO stdout;",
2361 fmtQualifiedDumpable(tbinfo),
2362 column_list);
2363 }
2364 res = ExecuteSqlQuery(fout, q->data, PGRES_COPY_OUT);

Callers

nothing calls this directly

Calls 15

createPQExpBufferFunction · 0.85
fmtCopyColumnListFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendPQExpBufferFunction · 0.85
ExecuteSqlQueryFunction · 0.85
PQclearFunction · 0.85
destroyPQExpBufferFunction · 0.85
PQgetCopyDataFunction · 0.85
WriteDataFunction · 0.85
PQfreememFunction · 0.85
archprintfFunction · 0.85
PQerrorMessageFunction · 0.85

Tested by

no test coverage detected