--- pg_dump.c.old Fri Aug 9 19:41:08 2002 +++ pg_dump.c Fri Aug 9 19:28:34 2002 @@ -128,6 +128,7 @@ TableInfo *tblinfo; int tblidx; bool oids; + const char *select_command; } DumpContext; static void @@ -390,6 +391,7 @@ { const DumpContext *dctx = (DumpContext *) dctxv; const char *classname = dctx->tblinfo[dctx->tblidx].relname; + const char *select_command = dctx->select_command; PGresult *res; PQExpBuffer q = createPQExpBuffer(); @@ -397,9 +399,23 @@ int field; if (fout->remoteVersion >= 70100) - appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT * FROM ONLY %s", fmtId(classname, force_quotes)); + if (select_command) + { + appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR %s", select_command); + } + else + { + appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT * FROM ONLY %s", fmtId(classname, force_quotes)); + } else - appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT * FROM %s", fmtId(classname, force_quotes)); + if (select_command) + { + appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR %s", select_command); + } + else + { + appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR SELECT * FROM %s", fmtId(classname, force_quotes)); + } res = PQexec(g_conn, q->data); if (!res || @@ -547,7 +563,7 @@ */ static void dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout, - const char *onlytable, const bool oids, const bool force_quotes) + const char *onlytable, const bool oids, const bool force_quotes, const char *select_command) { int i; DataDumperPtr dumpFn; @@ -587,6 +603,7 @@ dumpCtx->tblinfo = (TableInfo *) tblinfo; dumpCtx->tblidx = i; dumpCtx->oids = oids; + dumpCtx->select_command = NULL; if (!dumpData) { @@ -602,6 +619,10 @@ /* Restore using INSERT */ dumpFn = dumpClasses_dumpData; copyStmt = NULL; + if (onlytable && (strcmp(classname, onlytable) == 0)) + { + dumpCtx->select_command = select_command; + } } ArchiveEntry(fout, tblinfo[i].oid, tblinfo[i].relname, @@ -648,6 +669,7 @@ const char *pghost = NULL; const char *pgport = NULL; const char *username = NULL; + const char *select_command = NULL; char *tablename = NULL; bool oids = false; TableInfo *tblinfo; @@ -694,6 +716,7 @@ {"no-privileges", no_argument, NULL, 'x'}, {"no-acl", no_argument, NULL, 'x'}, {"compress", required_argument, NULL, 'Z'}, + {"where-clause", required_argument, NULL, 'w'}, {"help", no_argument, NULL, '?'}, {"version", no_argument, NULL, 'V'}, @@ -748,9 +771,9 @@ } #ifdef HAVE_GETOPT_LONG - while ((c = getopt_long(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:V?", long_options, &optindex)) != -1) + while ((c = getopt_long(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:w:V?", long_options, &optindex)) != -1) #else - while ((c = getopt(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:V?-")) != -1) + while ((c = getopt(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:w:V?-")) != -1) #endif { @@ -881,6 +904,9 @@ case 'v': /* verbose */ g_verbose = true; break; + case 'w': /* select query */ + select_command = optarg; + break; case 'W': force_password = true; @@ -1063,7 +1089,7 @@ tblinfo = dumpSchema(g_fout, &numTables, tablename, aclsSkip, oids, schemaOnly, dataOnly); if (!schemaOnly) - dumpClasses(tblinfo, numTables, g_fout, tablename, oids, force_quotes); + dumpClasses(tblinfo, numTables, g_fout, tablename, oids, force_quotes, select_command); if (outputBlobs) ArchiveEntry(g_fout, "0", "BLOBS", "BLOBS", NULL, "", "", "", "", dumpBlobs, 0);