8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.241 2005/05/01 18 :56:18 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.242 2005/05/06 02 :56:42 momjian Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -818,17 +818,13 @@ DoCopy(const CopyStmt *stmt)
818
818
escape = quote ;
819
819
}
820
820
821
- /*
822
- * Only single-character delimiter strings are supported.
823
- */
821
+ /* Only single-character delimiter strings are supported. */
824
822
if (strlen (delim )!= 1 )
825
823
ereport (ERROR ,
826
824
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
827
825
errmsg ("COPY delimiter must be a single character" )));
828
826
829
- /*
830
- * Check quote
831
- */
827
+ /* Check quote */
832
828
if (!csv_mode && quote != NULL )
833
829
ereport (ERROR ,
834
830
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -839,9 +835,7 @@ DoCopy(const CopyStmt *stmt)
839
835
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
840
836
errmsg ("COPY quote must be a single character" )));
841
837
842
- /*
843
- * Check escape
844
- */
838
+ /* Check escape */
845
839
if (!csv_mode && escape != NULL )
846
840
ereport (ERROR ,
847
841
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -852,9 +846,7 @@ DoCopy(const CopyStmt *stmt)
852
846
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
853
847
errmsg ("COPY escape must be a single character" )));
854
848
855
- /*
856
- * Check force_quote
857
- */
849
+ /* Check force_quote */
858
850
if (!csv_mode && force_quote != NIL )
859
851
ereport (ERROR ,
860
852
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -864,9 +856,7 @@ DoCopy(const CopyStmt *stmt)
864
856
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
865
857
errmsg ("COPY force quote only available using COPY TO" )));
866
858
867
- /*
868
- * Check force_notnull
869
- */
859
+ /* Check force_notnull */
870
860
if (!csv_mode && force_notnull != NIL )
871
861
ereport (ERROR ,
872
862
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -876,25 +866,19 @@ DoCopy(const CopyStmt *stmt)
876
866
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
877
867
errmsg ("COPY force not null only available using COPY FROM" )));
878
868
879
- /*
880
- * Don't allow the delimiter to appear in the null string.
881
- */
869
+ /* Don't allow the delimiter to appear in the null string. */
882
870
if (strchr (null_print ,delim [0 ])!= NULL )
883
871
ereport (ERROR ,
884
872
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
885
873
errmsg ("COPY delimiter must not appear in the NULL specification" )));
886
874
887
- /*
888
- * Don't allow the csv quote char to appear in the null string.
889
- */
875
+ /* Don't allow the csv quote char to appear in the null string. */
890
876
if (csv_mode && strchr (null_print ,quote [0 ])!= NULL )
891
877
ereport (ERROR ,
892
878
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
893
879
errmsg ("CSV quote character must not appear in the NULL specification" )));
894
880
895
- /*
896
- * Open and lock the relation, using the appropriate lock type.
897
- */
881
+ /* Open and lock the relation, using the appropriate lock type. */
898
882
rel = heap_openrv (relation , (is_from ?RowExclusiveLock :AccessShareLock ));
899
883
900
884
/* check read-only transaction */
@@ -916,23 +900,17 @@ DoCopy(const CopyStmt *stmt)
916
900
errhint ("Anyone can COPY to stdout or from stdin. "
917
901
"psql's \\copy command also works for anyone." )));
918
902
919
- /*
920
- * Don't allow COPY w/ OIDs to or from a table without them
921
- */
903
+ /* Don't allow COPY w/ OIDs to or from a table without them */
922
904
if (oids && !rel -> rd_rel -> relhasoids )
923
905
ereport (ERROR ,
924
906
(errcode (ERRCODE_UNDEFINED_COLUMN ),
925
907
errmsg ("table \"%s\" does not have OIDs" ,
926
908
RelationGetRelationName (rel ))));
927
909
928
- /*
929
- * Generate or convert list of attributes to process
930
- */
910
+ /* Generate or convert list of attributes to process */
931
911
attnumlist = CopyGetAttnums (rel ,attnamelist );
932
912
933
- /*
934
- * Check that FORCE QUOTE references valid COPY columns
935
- */
913
+ /* Check that FORCE QUOTE references valid COPY columns */
936
914
if (force_quote )
937
915
{
938
916
TupleDesc tupDesc = RelationGetDescr (rel );
@@ -953,9 +931,7 @@ DoCopy(const CopyStmt *stmt)
953
931
}
954
932
}
955
933
956
- /*
957
- * Check that FORCE NOT NULL references valid COPY columns
958
- */
934
+ /* Check that FORCE NOT NULL references valid COPY columns */
959
935
if (force_notnull )
960
936
{
961
937
ListCell * cur ;
@@ -976,9 +952,7 @@ DoCopy(const CopyStmt *stmt)
976
952
}
977
953
}
978
954
979
- /*
980
- * Set up variables to avoid per-attribute overhead.
981
- */
955
+ /* Set up variables to avoid per-attribute overhead. */
982
956
initStringInfo (& attribute_buf );
983
957
initStringInfo (& line_buf );
984
958
line_buf_converted = false;
@@ -1188,9 +1162,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
1188
1162
num_phys_attrs = tupDesc -> natts ;
1189
1163
attr_count = list_length (attnumlist );
1190
1164
1191
- /*
1192
- * Get info about the columns we need to process.
1193
- */
1165
+ /* Get info about the columns we need to process. */
1194
1166
out_functions = (FmgrInfo * )palloc (num_phys_attrs * sizeof (FmgrInfo ));
1195
1167
force_quote = (bool * )palloc (num_phys_attrs * sizeof (bool ));
1196
1168
foreach (cur ,attnumlist )
@@ -1596,9 +1568,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1596
1568
}
1597
1569
}
1598
1570
1599
- /*
1600
- * Prepare to catch AFTER triggers.
1601
- */
1571
+ /* Prepare to catch AFTER triggers. */
1602
1572
AfterTriggerBeginQuery ();
1603
1573
1604
1574
/*
@@ -1743,9 +1713,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1743
1713
}
1744
1714
}
1745
1715
1746
- /*
1747
- * Loop to read the user attributes on the line.
1748
- */
1716
+ /* Loop to read the user attributes on the line. */
1749
1717
foreach (cur ,attnumlist )
1750
1718
{
1751
1719
int attnum = lfirst_int (cur );
@@ -1869,9 +1837,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1869
1837
nulls [defmap [i ]]= ' ' ;
1870
1838
}
1871
1839
1872
- /*
1873
- * Next apply any domain constraints
1874
- */
1840
+ /* Next apply any domain constraints */
1875
1841
if (hasConstraints )
1876
1842
{
1877
1843
ParamExecData * prmdata = & econtext -> ecxt_param_exec_vals [0 ];
@@ -1898,17 +1864,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1898
1864
}
1899
1865
}
1900
1866
1901
- /*
1902
- * And now we can form the input tuple.
1903
- */
1867
+ /* And now we can form the input tuple. */
1904
1868
tuple = heap_formtuple (tupDesc ,values ,nulls );
1905
1869
1906
1870
if (oids && file_has_oids )
1907
1871
HeapTupleSetOid (tuple ,loaded_oid );
1908
1872
1909
- /*
1910
- * Triggers and stuff need to be invoked in query context.
1911
- */
1873
+ /* Triggers and stuff need to be invoked in query context. */
1912
1874
MemoryContextSwitchTo (oldcontext );
1913
1875
1914
1876
skip_tuple = false;
@@ -1935,15 +1897,11 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1935
1897
/* Place tuple in tuple slot */
1936
1898
ExecStoreTuple (tuple ,slot ,InvalidBuffer , false);
1937
1899
1938
- /*
1939
- * Check the constraints of the tuple
1940
- */
1900
+ /* Check the constraints of the tuple */
1941
1901
if (rel -> rd_att -> constr )
1942
1902
ExecConstraints (resultRelInfo ,slot ,estate );
1943
1903
1944
- /*
1945
- * OK, store the tuple and create index entries for it
1946
- */
1904
+ /* OK, store the tuple and create index entries for it */
1947
1905
simple_heap_insert (rel ,tuple );
1948
1906
1949
1907
if (resultRelInfo -> ri_NumIndices > 0 )
@@ -1954,21 +1912,15 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1954
1912
}
1955
1913
}
1956
1914
1957
- /*
1958
- * Done, clean up
1959
- */
1915
+ /* Done, clean up */
1960
1916
error_context_stack = errcontext .previous ;
1961
1917
1962
1918
MemoryContextSwitchTo (oldcontext );
1963
1919
1964
- /*
1965
- * Execute AFTER STATEMENT insertion triggers
1966
- */
1920
+ /* Execute AFTER STATEMENT insertion triggers */
1967
1921
ExecASInsertTriggers (estate ,resultRelInfo );
1968
1922
1969
- /*
1970
- * Handle queued AFTER triggers
1971
- */
1923
+ /* Handle queued AFTER triggers */
1972
1924
AfterTriggerEndQuery (estate );
1973
1925
1974
1926
pfree (values );
@@ -2255,9 +2207,7 @@ CopyReadLine(char * quote, char * escape)
2255
2207
}
2256
2208
}/* end of outer loop */
2257
2209
2258
- /*
2259
- * Done reading the line. Convert it to server encoding.
2260
- */
2210
+ /* Done reading the line. Convert it to server encoding. */
2261
2211
if (change_encoding )
2262
2212
{
2263
2213
cvt = (char * )pg_client_to_server ((unsignedchar * )line_buf .data ,
@@ -2457,28 +2407,22 @@ CopyReadAttributeCSV(const char *delim, const char *null_print, char *quote,
2457
2407
break ;
2458
2408
c = line_buf .data [line_buf .cursor ++ ];
2459
2409
2460
- /*
2461
- * unquoted field delimiter
2462
- */
2410
+ /* unquoted field delimiter */
2463
2411
if (!in_quote && c == delimc )
2464
2412
{
2465
2413
* result = NORMAL_ATTR ;
2466
2414
break ;
2467
2415
}
2468
2416
2469
- /*
2470
- * start of quoted field (or part of field)
2471
- */
2417
+ /* start of quoted field (or part of field) */
2472
2418
if (!in_quote && c == quotec )
2473
2419
{
2474
2420
saw_quote = true;
2475
2421
in_quote = true;
2476
2422
continue ;
2477
2423
}
2478
2424
2479
- /*
2480
- * escape within a quoted field
2481
- */
2425
+ /* escape within a quoted field */
2482
2426
if (in_quote && c == escapec )
2483
2427
{
2484
2428
/*