diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index ed67a2499b704572a66e1bab8260da0c53ae49f2..7d1e62abfce6818b24fa5cf3a02c4f62373a42e0 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -809,7 +809,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
 	{
 		instr_time	start;
 		instr_time	duration;
-		uint64		rows = 0;
+		uint64		rows;
 		BufferUsage bufusage_start,
 					bufusage;
 		uint32		queryId;
@@ -840,7 +840,15 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
 
 		/* parse command tag to retrieve the number of affected rows. */
 		if (completionTag &&
-			sscanf(completionTag, "COPY " UINT64_FORMAT, &rows) != 1)
+			strncmp(completionTag, "COPY ", 5) == 0)
+		{
+#ifdef HAVE_STRTOULL
+			rows = strtoull(completionTag + 5, NULL, 10);
+#else
+			rows = strtoul(completionTag + 5, NULL, 10);
+#endif
+		}
+		else
 			rows = 0;
 
 		/* calc differences of buffer counters. */