Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf906e07

Browse files
committed
Make sure we wait for protocol-level EOF when ending binary COPY IN.
The previous coding just terminated the COPY immediately after seeingthe EOF marker (-1 where a row field count is expected). The expectedCopyDone or CopyFail message just got thrown away later, since we weren'tin COPY mode anymore. This behavior complicated matters for the JDBCdriver, and arguably was the wrong thing in any case since a CopyFailmessage after the marker wouldn't be honored.Note that there is a behavioral change here: extra data after the EOFmarker was silently ignored before, but now it will cause an error.Hence not back-patching, although this is arguably a bug.Per report and patch by Kris Jurka.
1 parentaf0161e commitf906e07

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

‎src/backend/commands/copy.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.329 2010/08/13 20:10:50 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.330 2010/09/18 20:10:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2058,9 +2058,34 @@ CopyFrom(CopyState cstate)
20582058
int16fld_count;
20592059
ListCell*cur;
20602060

2061-
if (!CopyGetInt16(cstate,&fld_count)||
2062-
fld_count==-1)
2061+
if (!CopyGetInt16(cstate,&fld_count))
20632062
{
2063+
/* EOF detected (end of file, or protocol-level EOF) */
2064+
done= true;
2065+
break;
2066+
}
2067+
2068+
if (fld_count==-1)
2069+
{
2070+
/*
2071+
* Received EOF marker. In a V3-protocol copy, wait for
2072+
* the protocol-level EOF, and complain if it doesn't come
2073+
* immediately. This ensures that we correctly handle
2074+
* CopyFail, if client chooses to send that now.
2075+
*
2076+
* Note that we MUST NOT try to read more data in an
2077+
* old-protocol copy, since there is no protocol-level EOF
2078+
* marker then. We could go either way for copy from file,
2079+
* but choose to throw error if there's data after the EOF
2080+
* marker, for consistency with the new-protocol case.
2081+
*/
2082+
chardummy;
2083+
2084+
if (cstate->copy_dest!=COPY_OLD_FE&&
2085+
CopyGetData(cstate,&dummy,1,1)>0)
2086+
ereport(ERROR,
2087+
(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
2088+
errmsg("received copy data after EOF marker")));
20642089
done= true;
20652090
break;
20662091
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp