Here is a new submission with the expected "context diff format".
Dear PostgreSQL developers,
Plese find attached a patch so that:
Make "psql -1 < file.sql" work as with "-f"
Make psql --single-transaction option work on a non-interactive
standard input as well, so that "psql -1 < input.sql" behaves as
"psql -1 -f input.sql".
This saner/less error-prone behavior was discussed in this thread back in
June:
http://archives.postgresql.org/pgsql-hackers/2012-06/msg00785.php
I have tested it manually and it works for me. I'm not sure this is the best
possible implementation, but it is a small diff one. I haven't found a place
in the regression tests where "psql" could be tested with different options.
Did I miss something?
--
Fabien.
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
***************
*** 512,521 **** PostgreSQL documentation
<listitem>
<para>
When <application>psql</application> executes a script with the
! <option>-f</> option, adding this option wraps
! <command>BEGIN</>/<command>COMMIT</> around the script to execute it
! as a single transaction. This ensures that either all the commands
! complete successfully, or no changes are applied.
</para>
<para>
--- 512,521 ----
<listitem>
<para>
When <application>psql</application> executes a script with the
! <option>-f</> option or from a non-interactive standard input, adding
! this option wraps <command>BEGIN</>/<command>COMMIT</> around the script
! to execute it as a single transaction. This ensures that either all
! the commands complete successfully, or no changes are applied.
</para>
<para>
*** a/src/bin/psql/help.c
--- b/src/bin/psql/help.c
***************
*** 97,103 **** usage(void)
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
printf(_(" -1 (\"one\"), --single-transaction\n"
! " execute command file as a single transaction\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nInput and output options:\n"));
--- 97,104 ----
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
printf(_(" -1 (\"one\"), --single-transaction\n"
! " execute command file or non-interactive stdin\n"
! " as a single transaction\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nInput and output options:\n"));
*** a/src/bin/psql/settings.h
--- b/src/bin/psql/settings.h
***************
*** 76,81 **** typedef struct _psqlSettings
--- 76,82 ----
bool notty; /* stdin or stdout is not a tty (as determined
* on startup) */
+ bool stdin_notty; /* stdin is not a tty (on startup) */
enum trivalue getPassword; /* prompt the user for a username and password */
FILE *cur_cmd_source; /* describe the status of the current main
* loop */
*** a/src/bin/psql/startup.c
--- b/src/bin/psql/startup.c
***************
*** 133,139 **** main(int argc, char *argv[])
/* We must get COLUMNS here before readline() sets it */
pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
! pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
pset.getPassword = TRI_DEFAULT;
--- 133,140 ----
/* We must get COLUMNS here before readline() sets it */
pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
! pset.stdin_notty = !isatty(fileno(stdin));
! pset.notty = (pset.stdin_notty || !isatty(fileno(stdout)));
pset.getPassword = TRI_DEFAULT;
***************
*** 314,320 **** main(int argc, char *argv[])
if (!pset.notty)
initializeInput(options.no_readline ? 0 : 1);
! successResult = MainLoop(stdin);
}
/* clean up */
--- 315,326 ----
if (!pset.notty)
initializeInput(options.no_readline ? 0 : 1);
! if (options.single_txn && pset.stdin_notty)
! /* stdin is NOT a tty and -1, process as a file */
! successResult = process_file("-", true, false);
! else
! /* no single transation, process as if interactive */
! successResult = MainLoop(stdin);
}
/* clean up */
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers