On Fri, 6 Aug 2010, James William Pye wrote:
On Aug 6, 2010, at 4:31 PM, Kris Jurka wrote:
<binary-copy-end-v2.patch>
I think there's a snag in the patch:
postgres=# COPY data FROM '/Users/jwp/DATA.bcopy' WITH BINARY;
ERROR: row field count is -1, expected 1
CONTEXT: COPY data, line 4
Probably a quick/small fix away, I imagine.
Hmm, not quite sure why that is. That seems to imply that it's not using
V3 protocol, but I thought binary copy could only be used with the V3
protocol. In any case, I think this new patch is more bulletproof.
Kris Jurka
*** a/src/backend/commands/copy.c
--- b/src/backend/commands/copy.c
***************
*** 2058,2069 **** CopyFrom(CopyState cstate)
int16 fld_count;
ListCell *cur;
! if (!CopyGetInt16(cstate, &fld_count) ||
! fld_count == -1)
{
done = true;
break;
}
if (fld_count != attr_count)
ereport(ERROR,
--- 2058,2090 ----
int16 fld_count;
ListCell *cur;
! if (!CopyGetInt16(cstate, &fld_count))
{
done = true;
break;
}
+
+ if (fld_count == -1)
+ {
+ /*
+ * Reached EOF. In protocol version 3, we must
wait for
+ * the protocol end of copy (CopyDone/Fail).
If we
+ * receive any more copy data after EOF,
complain.
+ */
+ if (cstate->copy_dest == COPY_NEW_FE)
+ {
+ int8 unused;
+ if (CopyGetData(cstate, &unused,
sizeof(unused), sizeof(unused)))
+ {
+ ereport(ERROR,
+
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
+
errmsg("received copy data after EOF marker")));
+ }
+ }
+
+ done = true;
+ break;
+ }
if (fld_count != attr_count)
ereport(ERROR,
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers