psql -f -
authorBruce Momjian <bruce@momjian.us>
Tue, 1 Dec 2009 22:34:33 +0000 (22:34 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 1 Dec 2009 22:34:33 +0000 (22:34 +0000)
Adjust psql -f - to behave like a normal file and honor the -1 flag.

Report from Robert Haas

src/bin/psql/command.c
src/bin/psql/startup.c

index 5a356b9b5ee17232aaac4fe03889ca967ab894aa..3f32f5d9d99b6a05bdcbb137592c63faf7222ea3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2009, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.211 2009/11/22 05:20:41 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.212 2009/12/01 22:34:33 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -1691,8 +1691,13 @@ process_file(char *filename, bool single_txn)
        if (!filename)
                return EXIT_FAILURE;
 
-       canonicalize_path(filename);
-       fd = fopen(filename, PG_BINARY_R);
+       if (strcmp(filename, "-") != 0)
+       {
+               canonicalize_path(filename);
+               fd = fopen(filename, PG_BINARY_R);
+       }
+       else
+               fd = stdin;
 
        if (!fd)
        {
index 61658de7c33f30fe85d326fa903f38bb0208a5c7..1ce4d7533c8fc2743ca2e29e5e856287af0f9139 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2009, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.156 2009/04/05 04:19:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.157 2009/12/01 22:34:33 momjian Exp $
  */
 #include "postgres_fe.h"
 
@@ -225,7 +225,7 @@ main(int argc, char *argv[])
        /*
         * process file given by -f
         */
-       if (options.action == ACT_FILE && strcmp(options.action_string, "-") != 0)
+       if (options.action == ACT_FILE)
        {
                if (!options.no_psqlrc)
                        process_psqlrc(argv[0]);