From cab19af9fb573f87b713b604a99799a6a242668b Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 5 Jul 2011 12:04:40 -0400
Subject: [PATCH] Fix psql's counting of script file line numbers during COPY.

handleCopyIn incremented pset.lineno for each line of COPY data read from
a file.  This is correct when reading from the current script file (i.e.,
we are doing COPY FROM STDIN followed by in-line data), but it's wrong if
the data is coming from some other file.  Per bug #6083 from Steve Haslam.
Back-patch to all supported versions.
---
 src/bin/psql/copy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 5e69d29b6cb..ebe5ee9ea55 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -586,7 +586,8 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary)
 				}
 			}
 
-			pset.lineno++;
+			if (copystream == pset.cur_cmd_source)
+				pset.lineno++;
 		}
 	}
 
-- 
GitLab