* dumpTableData - * dump the contents of a single table * * Actually, this just makes an ArchiveEntry for the table contents. */
| 2778 | * Actually, this just makes an ArchiveEntry for the table contents. |
| 2779 | */ |
| 2780 | static void |
| 2781 | dumpTableData(Archive *fout, const TableDataInfo *tdinfo) |
| 2782 | { |
| 2783 | DumpOptions *dopt = fout->dopt; |
| 2784 | TableInfo *tbinfo = tdinfo->tdtable; |
| 2785 | PQExpBuffer copyBuf = createPQExpBuffer(); |
| 2786 | PQExpBuffer clistBuf = createPQExpBuffer(); |
| 2787 | DataDumperPtr dumpFn; |
| 2788 | char *tdDefn = NULL; |
| 2789 | char *copyStmt; |
| 2790 | const char *copyFrom; |
| 2791 | |
| 2792 | /* We had better have loaded per-column details about this table */ |
| 2793 | Assert(tbinfo->interesting); |
| 2794 | |
| 2795 | /* |
| 2796 | * When load-via-partition-root is set or forced, get the root table name |
| 2797 | * for the partition table, so that we can reload data through the root |
| 2798 | * table. Then construct a comment to be inserted into the TOC entry's |
| 2799 | * defn field, so that such cases can be identified reliably. |
| 2800 | */ |
| 2801 | if (tbinfo->ispartition && |
| 2802 | (dopt->load_via_partition_root || |
| 2803 | forcePartitionRootLoad(tbinfo))) |
| 2804 | { |
| 2805 | TableInfo *parentTbinfo; |
| 2806 | |
| 2807 | parentTbinfo = getRootTableInfo(tbinfo); |
| 2808 | copyFrom = fmtQualifiedDumpable(parentTbinfo); |
| 2809 | printfPQExpBuffer(copyBuf, "-- load via partition root %s", |
| 2810 | copyFrom); |
| 2811 | tdDefn = pg_strdup(copyBuf->data); |
| 2812 | } |
| 2813 | else |
| 2814 | copyFrom = fmtQualifiedDumpable(tbinfo); |
| 2815 | |
| 2816 | if (dopt->dump_inserts == 0) |
| 2817 | { |
| 2818 | /* Dump/restore using COPY */ |
| 2819 | dumpFn = dumpTableData_copy; |
| 2820 | /* must use 2 steps here 'cause fmtId is nonreentrant */ |
| 2821 | printfPQExpBuffer(copyBuf, "COPY %s ", |
| 2822 | copyFrom); |
| 2823 | appendPQExpBuffer(copyBuf, "%s FROM stdin;\n", |
| 2824 | fmtCopyColumnList(tbinfo, clistBuf)); |
| 2825 | copyStmt = copyBuf->data; |
| 2826 | } |
| 2827 | else |
| 2828 | { |
| 2829 | /* Restore using INSERT */ |
| 2830 | dumpFn = dumpTableData_insert; |
| 2831 | copyStmt = NULL; |
| 2832 | } |
| 2833 | |
| 2834 | /* |
| 2835 | * Note: although the TableDataInfo is a full DumpableObject, we treat its |
| 2836 | * dependency on its table as "special" and pass it to ArchiveEntry now. |
| 2837 | * See comments for BuildArchiveDependencies. |
no test coverage detected