File tree 8 files changed +29
-9
lines changed
8 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -50,14 +50,12 @@ CREATE USER MAPPING FOR regress_no_priv_user SERVER file_server;
50
50
-- validator tests
51
51
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'xml'); -- ERROR
52
52
ERROR: COPY format "xml" not recognized
53
- CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'text', header 'true'); -- ERROR
54
- ERROR: COPY HEADER available only in CSV mode
55
53
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'text', quote ':'); -- ERROR
56
54
ERROR: COPY quote available only in CSV mode
57
55
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'text', escape ':'); -- ERROR
58
56
ERROR: COPY escape available only in CSV mode
59
57
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'binary', header 'true'); -- ERROR
60
- ERROR: COPY HEADER available only in CSV mode
58
+ ERROR: cannot specify HEADER in BINARY mode
61
59
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'binary', quote ':'); -- ERROR
62
60
ERROR: COPY quote available only in CSV mode
63
61
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'binary', escape ':'); -- ERROR
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ CREATE USER MAPPING FOR regress_no_priv_user SERVER file_server;
56
56
57
57
-- validator tests
58
58
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format ' xml' ); -- ERROR
59
- CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format ' text' , header ' true' ); -- ERROR
60
59
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format ' text' , quote ' :' ); -- ERROR
61
60
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format ' text' , escape ' :' ); -- ERROR
62
61
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format ' binary' , header ' true' ); -- ERROR
Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
277
277
Specifies that the file contains a header line with the names of each
278
278
column in the file. On output, the first line contains the column
279
279
names from the table, and on input, the first line is ignored.
280
- This option is allowed only when using <literal>CSV </literal> format.
280
+ This option is not allowed when using <literal>binary </literal> format.
281
281
</para>
282
282
</listitem>
283
283
</varlistentry>
Original file line number Diff line number Diff line change @@ -555,10 +555,10 @@ ProcessCopyOptions(ParseState *pstate,
555
555
errmsg ("COPY delimiter cannot be \"%s\"" , opts_out -> delim )));
556
556
557
557
/* Check header */
558
- if (! opts_out -> csv_mode && opts_out -> header_line )
558
+ if (opts_out -> binary && opts_out -> header_line )
559
559
ereport (ERROR ,
560
560
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
561
- errmsg ("COPY HEADER available only in CSV mode" )));
561
+ errmsg ("cannot specify HEADER in BINARY mode" )));
562
562
563
563
/* Check quote */
564
564
if (!opts_out -> csv_mode && opts_out -> quote != NULL )
Original file line number Diff line number Diff line change @@ -863,8 +863,11 @@ DoCopyTo(CopyToState cstate)
863
863
864
864
colname = NameStr (TupleDescAttr (tupDesc , attnum - 1 )-> attname );
865
865
866
- CopyAttributeOutCSV (cstate , colname , false,
866
+ if (cstate -> opts .csv_mode )
867
+ CopyAttributeOutCSV (cstate , colname , false,
867
868
list_length (cstate -> attnumlist ) == 1 );
869
+ else
870
+ CopyAttributeOutText (cstate , colname );
868
871
}
869
872
870
873
CopySendEndOfRow (cstate );
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ typedef struct CopyFormatOptions
32
32
bool binary ; /* binary format? */
33
33
bool freeze ; /* freeze rows on loading? */
34
34
bool csv_mode ; /* Comma Separated Value format? */
35
- bool header_line ; /* CSV header line? */
35
+ bool header_line ; /* header line? */
36
36
char * null_print ; /* NULL marker string (server encoding!) */
37
37
int null_print_len ; /* length of same */
38
38
char * null_print_client ; /* same converted to file encoding */
Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ copy copytest3 to stdout csv header;
120
120
c1,"col with , comma","col with "" quote"
121
121
1,a,1
122
122
2,b,2
123
+ create temp table copytest4 (
124
+ c1 int,
125
+ "colname with tab: " text);
126
+ copy copytest4 from stdin (header);
127
+ copy copytest4 to stdout (header);
128
+ c1 colname with tab: \t
129
+ 1 a
130
+ 2 b
123
131
-- test copy from with a partitioned table
124
132
create table parted_copytest (
125
133
a int,
Original file line number Diff line number Diff line change @@ -160,6 +160,18 @@ this is just a line full of junk that would error out if parsed
160
160
161
161
copy copytest3 to stdout csv header;
162
162
163
+ create temp table copytest4 (
164
+ c1 int ,
165
+ " colname with tab: " text );
166
+
167
+ copy copytest4 from stdin (header);
168
+ this is just a line full of junk that would error out if parsed
169
+ 1 a
170
+ 2 b
171
+ \.
172
+
173
+ copy copytest4 to stdout (header);
174
+
163
175
-- test copy from with a partitioned table
164
176
create table parted_copytest (
165
177
a int ,
You can’t perform that action at this time.
0 commit comments