On Fri, 2005-12-16 at 15:56 -0500, Tom Lane wrote: > Simon Riggs <[EMAIL PROTECTED]> writes: > > On Fri, 2005-12-16 at 13:59 -0500, Tom Lane wrote: > >> Would -1 work, or just confuse people? > > > That was my preference, I just thought it wouldn't be popular... > > So I'll happily change that. > > OK. While you're at it, I didn't like the long name either ;-). > We do not use the abbrevation txn anywhere, so I think it's bad to > introduce it here. I'd vote for spelling out --single-transaction, > or maybe just --single. I believe you can abbreviate long switch names > to any unique prefix, so there's not really any more typing here.
Changes as discussed. "singletransaction.patch" attached. options: -1 or --single-transaction Functions work as described. Best Regards, Simon Riggs
Index: src/bin/pg_dump/pg_backup.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v retrieving revision 1.37 diff -c -r1.37 pg_backup.h *** src/bin/pg_dump/pg_backup.h 15 Oct 2005 02:49:38 -0000 1.37 --- src/bin/pg_dump/pg_backup.h 17 Dec 2005 16:51:25 -0000 *************** *** 115,120 **** --- 115,122 ---- int suppressDumpWarnings; /* Suppress output of WARNING entries * to stderr */ + bool single_txn; + } RestoreOptions; /* Index: src/bin/pg_dump/pg_backup_archiver.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v retrieving revision 1.118 diff -c -r1.118 pg_backup_archiver.c *** src/bin/pg_dump/pg_backup_archiver.c 22 Nov 2005 18:17:28 -0000 1.118 --- src/bin/pg_dump/pg_backup_archiver.c 17 Dec 2005 16:51:27 -0000 *************** *** 217,222 **** --- 217,225 ---- AH->stage = STAGE_PROCESSING; + if (ropt->single_txn) + ahprintf(AH, "BEGIN;\n\n"); + /* * Drop the items at the start, in reverse order */ *************** *** 365,370 **** --- 368,376 ---- } } + if (ropt->single_txn) + ahprintf(AH, "COMMIT;\n\n"); + if (AH->public.verbose) dumpTimestamp(AH, "Completed on", time(NULL)); Index: src/bin/pg_dump/pg_restore.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v retrieving revision 1.73 diff -c -r1.73 pg_restore.c *** src/bin/pg_dump/pg_restore.c 15 Oct 2005 02:49:39 -0000 1.73 --- src/bin/pg_dump/pg_restore.c 17 Dec 2005 16:51:27 -0000 *************** *** 111,116 **** --- 111,117 ---- {"use-list", 1, NULL, 'L'}, {"username", 1, NULL, 'U'}, {"verbose", 0, NULL, 'v'}, + {"single-transaction", 0, NULL, '1'}, /* * the following options don't have an equivalent short option letter, *************** *** 142,148 **** } } ! while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:", cmdopts, NULL)) != -1) { switch (c) --- 143,149 ---- } } ! while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:1", cmdopts, NULL)) != -1) { switch (c) *************** *** 185,193 **** --- 186,200 ---- opts->tocFile = strdup(optarg); break; + case 'n': /* Dump data for this schema only */ + opts->selTypes = 1; + opts->schemaNames = strdup(optarg); + break; + case 'O': opts->noOwner = 1; break; + case 'p': if (strlen(optarg) != 0) opts->pgport = strdup(optarg); *************** *** 223,233 **** opts->tableNames = strdup(optarg); break; - case 'n': /* Dump data for this schema only */ - opts->selTypes = 1; - opts->schemaNames = strdup(optarg); - break; - case 'u': opts->requirePassword = true; opts->username = simple_prompt("User name: ", 100, true); --- 230,235 ---- *************** *** 268,273 **** --- 270,280 ---- case 0: break; + case '1': /* Restore data in a single transaction */ + opts->single_txn = true; + opts->exit_on_error = true; + break; + default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); *************** *** 394,399 **** --- 401,407 ---- printf(_(" -X use-set-session-authorization, --use-set-session-authorization\n" " use SESSION AUTHORIZATION commands instead of\n" " OWNER TO commands\n")); + printf(_(" -1, --single-transaction restore as a single transaction\n")); printf(_("\nConnection options:\n")); printf(_(" -h, --host=HOSTNAME database server host or socket directory\n")); Index: src/bin/psql/command.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/command.c,v retrieving revision 1.155 diff -c -r1.155 command.c *** src/bin/psql/command.c 8 Dec 2005 21:18:22 -0000 1.155 --- src/bin/psql/command.c 17 Dec 2005 16:51:29 -0000 *************** *** 523,529 **** else { expand_tilde(&fname); ! success = (process_file(fname) == EXIT_SUCCESS); free(fname); } } --- 523,529 ---- else { expand_tilde(&fname); ! success = (process_file(fname, false) == EXIT_SUCCESS); free(fname); } } *************** *** 1317,1327 **** * MainLoop() error code. */ int ! process_file(char *filename) { FILE *fd; int result; char *oldfilename; if (!filename) return EXIT_FAILURE; --- 1317,1328 ---- * MainLoop() error code. */ int ! process_file(char *filename, bool single_txn) { FILE *fd; int result; char *oldfilename; + PGresult *res; if (!filename) return EXIT_FAILURE; *************** *** 1337,1343 **** --- 1338,1350 ---- oldfilename = pset.inputfile; pset.inputfile = filename; + + if (single_txn) + res = PSQLexec("BEGIN", false); result = MainLoop(fd); + if (single_txn) + res = PSQLexec("COMMIT", false); + fclose(fd); pset.inputfile = oldfilename; return result; Index: src/bin/psql/command.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/command.h,v retrieving revision 1.22 diff -c -r1.22 command.h *** src/bin/psql/command.h 1 Jan 2005 05:43:08 -0000 1.22 --- src/bin/psql/command.h 17 Dec 2005 16:51:29 -0000 *************** *** 28,34 **** extern backslashResult HandleSlashCmds(PsqlScanState scan_state, PQExpBuffer query_buf); ! extern int process_file(char *filename); extern bool do_pset(const char *param, const char *value, --- 28,34 ---- extern backslashResult HandleSlashCmds(PsqlScanState scan_state, PQExpBuffer query_buf); ! extern int process_file(char *filename, bool single_txn); extern bool do_pset(const char *param, const char *value, Index: src/bin/psql/help.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/help.c,v retrieving revision 1.106 diff -c -r1.106 help.c *** src/bin/psql/help.c 15 Oct 2005 02:49:40 -0000 1.106 --- src/bin/psql/help.c 17 Dec 2005 16:51:29 -0000 *************** *** 92,97 **** --- 92,98 ---- printf(_(" -d DBNAME specify database name to connect to (default: \"%s\")\n"), env); puts(_(" -c COMMAND run only single command (SQL or internal) and exit")); puts(_(" -f FILENAME execute commands from file, then exit")); + puts(_(" -1 (numeral) execute command file as a single transaction")); puts(_(" -l list available databases, then exit")); puts(_(" -v NAME=VALUE set psql variable NAME to VALUE")); puts(_(" -X do not read startup file (~/.psqlrc)")); Index: src/bin/psql/startup.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/startup.c,v retrieving revision 1.128 diff -c -r1.128 startup.c *** src/bin/psql/startup.c 22 Nov 2005 18:17:29 -0000 1.128 --- src/bin/psql/startup.c 17 Dec 2005 16:51:30 -0000 *************** *** 76,81 **** --- 76,82 ---- char *action_string; bool no_readline; bool no_psqlrc; + bool single_txn; }; static int parse_version(const char *versionString); *************** *** 268,274 **** if (!options.no_psqlrc) process_psqlrc(argv[0]); ! successResult = process_file(options.action_string); } /* --- 269,275 ---- if (!options.no_psqlrc) process_psqlrc(argv[0]); ! successResult = process_file(options.action_string, options.single_txn); } /* *************** *** 425,430 **** --- 426,432 ---- {"list", no_argument, NULL, 'l'}, {"log-file", required_argument, NULL, 'L'}, {"no-readline", no_argument, NULL, 'n'}, + {"single-transaction", no_argument, NULL, '1'}, {"output", required_argument, NULL, 'o'}, {"port", required_argument, NULL, 'p'}, {"pset", required_argument, NULL, 'P'}, *************** *** 453,459 **** memset(options, 0, sizeof *options); ! while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1) { switch (c) --- 455,461 ---- memset(options, 0, sizeof *options); ! while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?1", long_options, &optindex)) != -1) { switch (c) *************** *** 606,611 **** --- 608,616 ---- case 'X': options->no_psqlrc = true; break; + case '1': + options->single_txn = true; + break; case '?': /* Actual help option given */ if (strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0) *************** *** 690,698 **** sprintf(psqlrc, "%s-%s", filename, PG_VERSION); if (access(psqlrc, R_OK) == 0) ! (void) process_file(psqlrc); else if (access(filename, R_OK) == 0) ! (void) process_file(filename); free(psqlrc); } --- 695,703 ---- sprintf(psqlrc, "%s-%s", filename, PG_VERSION); if (access(psqlrc, R_OK) == 0) ! (void) process_file(psqlrc, false); else if (access(filename, R_OK) == 0) ! (void) process_file(filename, false); free(psqlrc); }
---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match