binary-copy-end.patch

text/plain

Filename: binary-copy-end.patch
Type: text/plain
Part: 0
Message: Re: Trouble with COPY IN

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: context
File+
src/backend/commands/copy.c 20 0
*** 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,2087 ----
  			int16		fld_count;
  			ListCell   *cur;
  
! 			if (!CopyGetInt16(cstate, &fld_count))
  			{
  				done = true;
  				break;
  			}
+ 			
+ 			if (fld_count == -1)
+ 			{
+ 				/*
+ 				 * Reached EOF.  In protocol version 3, we should ignore
+ 				 * anything after the end of copy data marker up to the
+ 				 * protocol end of copy data (CopyDone/Fail).
+ 				 */
+ 				if (cstate->copy_dest == COPY_NEW_FE)
+ 				{
+ 					do
+ 					{
+ 						cstate->raw_buf_index = cstate->raw_buf_len;
+ 					} while (CopyLoadRawBuf(cstate));
+ 						continue;
+ 				}
+ 				done = true;
+ 				break;
+ 			}
  
  			if (fld_count != attr_count)
  				ereport(ERROR,