There is a long-standing oddity in psql that running

psql -f foo.sql

returns error messages with file name and line number, like

psql:foo.sql:1: ERROR:  syntax error at or near "foo"

but running

psql < foo.sql does not.  I suggest we change the latter to print

psql:<stdin>:1: ERROR:  syntax error at or near "foo"

Other examples for the use of the spelling "<stdin>" in this context
include gcc and slonik.

Error messages printed in interactive mode will not be affected, of
course.

Patch attached.
diff --git i/src/bin/psql/common.c w/src/bin/psql/common.c
index 5ab736e..18260f1 100644
--- i/src/bin/psql/common.c
+++ w/src/bin/psql/common.c
@@ -166,6 +166,8 @@ psql_error(const char *fmt,...)
 
 	if (pset.inputfile)
 		fprintf(stderr, "%s:%s:" UINT64_FORMAT ": ", pset.progname, pset.inputfile, pset.lineno);
+	else if (!isatty(fileno(stdin)))
+		fprintf(stderr, "%s:<stdin>:" UINT64_FORMAT ": ", pset.progname, pset.lineno);
 	va_start(ap, fmt);
 	vfprintf(stderr, _(fmt), ap);
 	va_end(ap);
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to