Hello, I thought I would try and knock off the "count number of rows inserted when using the Copy command" from the todo list.
The attached diff works for me on non-binary files using latest cvs It seems though that I am making a redundant elog(INFO) call though. If I run gmake check the Copy command does fail though.... Any comments or suggestions would be appreciated. I was going to post this on the Hackers list but I am still waiting to reply to the initial confirmation email(over an hour ago). I received the patch list confirmation instantly.
Index: copy.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/copy.c,v
retrieving revision 1.218
diff -u -r1.218 copy.c
--- copy.c 10 Feb 2004 01:55:24 -0000 1.218
+++ copy.c 10 Mar 2004 05:41:03 -0000
@@ -1784,6 +1784,30 @@
if (c == EOF)
{
result = true;
+
+/*Now report number of rows imported to user*/
+ /*don't count the end of file as a line imported*/
+ copy_lineno--;
+ if (copy_lineno > 1)
+ {
+ elog(INFO,"Copied lines %d from file %s",
+ copy_lineno, copy_relname);
+
+ }else if (copy_lineno == 1)
+ {
+ elog(INFO,"Copied 1 line from %s", copy_relname);
+ }
+ else if (copy_lineno == 0)
+ {
+ ereport(WARNING,(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
+ errmsg ("File used to import data is empty."),
+ errhint("Double check file name used")));
+ }else if (copy_lineno < 0)
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_BAD_COPY_FILE_FORMAT), errmsg("Rows copied were less than zero. Copy function has been broken"),
+ errhint("File a bug please")));
+ }
break;
}
if (c == '\r')
signature.asc
Description: This is a digitally signed message part
