mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Add HEADER support to COPY text format
The COPY CSV format supports the HEADER option to output a header line. This patch adds the same option to the default text format. On input, the HEADER option causes the first line to be skipped, same as with CSV. Author: Rémi Lapeyre <remi.lapeyre@lenstra.fr> Discussion: https://www.postgresql.org/message-id/flat/CAF1-J-0PtCWMeLtswwGV2M70U26n4g33gpe1rcKQqe6wVQDrFA@mail.gmail.com
This commit is contained in:
		@@ -555,10 +555,10 @@ ProcessCopyOptions(ParseState *pstate,
 | 
			
		||||
				 errmsg("COPY delimiter cannot be \"%s\"", opts_out->delim)));
 | 
			
		||||
 | 
			
		||||
	/* Check header */
 | 
			
		||||
	if (!opts_out->csv_mode && opts_out->header_line)
 | 
			
		||||
	if (opts_out->binary && opts_out->header_line)
 | 
			
		||||
		ereport(ERROR,
 | 
			
		||||
				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 | 
			
		||||
				 errmsg("COPY HEADER available only in CSV mode")));
 | 
			
		||||
				 errmsg("cannot specify HEADER in BINARY mode")));
 | 
			
		||||
 | 
			
		||||
	/* Check quote */
 | 
			
		||||
	if (!opts_out->csv_mode && opts_out->quote != NULL)
 | 
			
		||||
 
 | 
			
		||||
@@ -863,8 +863,11 @@ DoCopyTo(CopyToState cstate)
 | 
			
		||||
 | 
			
		||||
				colname = NameStr(TupleDescAttr(tupDesc, attnum - 1)->attname);
 | 
			
		||||
 | 
			
		||||
				CopyAttributeOutCSV(cstate, colname, false,
 | 
			
		||||
				if (cstate->opts.csv_mode)
 | 
			
		||||
					CopyAttributeOutCSV(cstate, colname, false,
 | 
			
		||||
									list_length(cstate->attnumlist) == 1);
 | 
			
		||||
				else
 | 
			
		||||
					CopyAttributeOutText(cstate, colname);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			CopySendEndOfRow(cstate);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user