88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -818,17 +818,13 @@ DoCopy(const CopyStmt *stmt)
818818escape = quote ;
819819}
820820
821- /*
822- * Only single-character delimiter strings are supported.
823- */
821+ /* Only single-character delimiter strings are supported. */
824822if (strlen (delim )!= 1 )
825823ereport (ERROR ,
826824(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
827825errmsg ("COPY delimiter must be a single character" )));
828826
829- /*
830- * Check quote
831- */
827+ /* Check quote */
832828if (!csv_mode && quote != NULL )
833829ereport (ERROR ,
834830(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -839,9 +835,7 @@ DoCopy(const CopyStmt *stmt)
839835(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
840836errmsg ("COPY quote must be a single character" )));
841837
842- /*
843- * Check escape
844- */
838+ /* Check escape */
845839if (!csv_mode && escape != NULL )
846840ereport (ERROR ,
847841(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -852,9 +846,7 @@ DoCopy(const CopyStmt *stmt)
852846(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
853847errmsg ("COPY escape must be a single character" )));
854848
855- /*
856- * Check force_quote
857- */
849+ /* Check force_quote */
858850if (!csv_mode && force_quote != NIL )
859851ereport (ERROR ,
860852(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -864,9 +856,7 @@ DoCopy(const CopyStmt *stmt)
864856(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
865857errmsg ("COPY force quote only available using COPY TO" )));
866858
867- /*
868- * Check force_notnull
869- */
859+ /* Check force_notnull */
870860if (!csv_mode && force_notnull != NIL )
871861ereport (ERROR ,
872862(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -876,25 +866,19 @@ DoCopy(const CopyStmt *stmt)
876866(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
877867errmsg ("COPY force not null only available using COPY FROM" )));
878868
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. */
882870if (strchr (null_print ,delim [0 ])!= NULL )
883871ereport (ERROR ,
884872(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
885873errmsg ("COPY delimiter must not appear in the NULL specification" )));
886874
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. */
890876if (csv_mode && strchr (null_print ,quote [0 ])!= NULL )
891877ereport (ERROR ,
892878(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
893879errmsg ("CSV quote character must not appear in the NULL specification" )));
894880
895- /*
896- * Open and lock the relation, using the appropriate lock type.
897- */
881+ /* Open and lock the relation, using the appropriate lock type. */
898882rel = heap_openrv (relation , (is_from ?RowExclusiveLock :AccessShareLock ));
899883
900884/* check read-only transaction */
@@ -916,23 +900,17 @@ DoCopy(const CopyStmt *stmt)
916900errhint ("Anyone can COPY to stdout or from stdin. "
917901"psql's \\copy command also works for anyone." )));
918902
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 */
922904if (oids && !rel -> rd_rel -> relhasoids )
923905ereport (ERROR ,
924906(errcode (ERRCODE_UNDEFINED_COLUMN ),
925907errmsg ("table \"%s\" does not have OIDs" ,
926908RelationGetRelationName (rel ))));
927909
928- /*
929- * Generate or convert list of attributes to process
930- */
910+ /* Generate or convert list of attributes to process */
931911attnumlist = CopyGetAttnums (rel ,attnamelist );
932912
933- /*
934- * Check that FORCE QUOTE references valid COPY columns
935- */
913+ /* Check that FORCE QUOTE references valid COPY columns */
936914if (force_quote )
937915{
938916TupleDesc tupDesc = RelationGetDescr (rel );
@@ -953,9 +931,7 @@ DoCopy(const CopyStmt *stmt)
953931}
954932}
955933
956- /*
957- * Check that FORCE NOT NULL references valid COPY columns
958- */
934+ /* Check that FORCE NOT NULL references valid COPY columns */
959935if (force_notnull )
960936{
961937ListCell * cur ;
@@ -976,9 +952,7 @@ DoCopy(const CopyStmt *stmt)
976952}
977953}
978954
979- /*
980- * Set up variables to avoid per-attribute overhead.
981- */
955+ /* Set up variables to avoid per-attribute overhead. */
982956initStringInfo (& attribute_buf );
983957initStringInfo (& line_buf );
984958line_buf_converted = false;
@@ -1188,9 +1162,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
11881162num_phys_attrs = tupDesc -> natts ;
11891163attr_count = list_length (attnumlist );
11901164
1191- /*
1192- * Get info about the columns we need to process.
1193- */
1165+ /* Get info about the columns we need to process. */
11941166out_functions = (FmgrInfo * )palloc (num_phys_attrs * sizeof (FmgrInfo ));
11951167force_quote = (bool * )palloc (num_phys_attrs * sizeof (bool ));
11961168foreach (cur ,attnumlist )
@@ -1596,9 +1568,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
15961568}
15971569}
15981570
1599- /*
1600- * Prepare to catch AFTER triggers.
1601- */
1571+ /* Prepare to catch AFTER triggers. */
16021572AfterTriggerBeginQuery ();
16031573
16041574/*
@@ -1743,9 +1713,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
17431713}
17441714}
17451715
1746- /*
1747- * Loop to read the user attributes on the line.
1748- */
1716+ /* Loop to read the user attributes on the line. */
17491717foreach (cur ,attnumlist )
17501718{
17511719int attnum = lfirst_int (cur );
@@ -1869,9 +1837,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
18691837nulls [defmap [i ]]= ' ' ;
18701838}
18711839
1872- /*
1873- * Next apply any domain constraints
1874- */
1840+ /* Next apply any domain constraints */
18751841if (hasConstraints )
18761842{
18771843ParamExecData * prmdata = & econtext -> ecxt_param_exec_vals [0 ];
@@ -1898,17 +1864,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
18981864}
18991865}
19001866
1901- /*
1902- * And now we can form the input tuple.
1903- */
1867+ /* And now we can form the input tuple. */
19041868tuple = heap_formtuple (tupDesc ,values ,nulls );
19051869
19061870if (oids && file_has_oids )
19071871HeapTupleSetOid (tuple ,loaded_oid );
19081872
1909- /*
1910- * Triggers and stuff need to be invoked in query context.
1911- */
1873+ /* Triggers and stuff need to be invoked in query context. */
19121874MemoryContextSwitchTo (oldcontext );
19131875
19141876skip_tuple = false;
@@ -1935,15 +1897,11 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
19351897/* Place tuple in tuple slot */
19361898ExecStoreTuple (tuple ,slot ,InvalidBuffer , false);
19371899
1938- /*
1939- * Check the constraints of the tuple
1940- */
1900+ /* Check the constraints of the tuple */
19411901if (rel -> rd_att -> constr )
19421902ExecConstraints (resultRelInfo ,slot ,estate );
19431903
1944- /*
1945- * OK, store the tuple and create index entries for it
1946- */
1904+ /* OK, store the tuple and create index entries for it */
19471905simple_heap_insert (rel ,tuple );
19481906
19491907if (resultRelInfo -> ri_NumIndices > 0 )
@@ -1954,21 +1912,15 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
19541912}
19551913}
19561914
1957- /*
1958- * Done, clean up
1959- */
1915+ /* Done, clean up */
19601916error_context_stack = errcontext .previous ;
19611917
19621918MemoryContextSwitchTo (oldcontext );
19631919
1964- /*
1965- * Execute AFTER STATEMENT insertion triggers
1966- */
1920+ /* Execute AFTER STATEMENT insertion triggers */
19671921ExecASInsertTriggers (estate ,resultRelInfo );
19681922
1969- /*
1970- * Handle queued AFTER triggers
1971- */
1923+ /* Handle queued AFTER triggers */
19721924AfterTriggerEndQuery (estate );
19731925
19741926pfree (values );
@@ -2255,9 +2207,7 @@ CopyReadLine(char * quote, char * escape)
22552207}
22562208}/* end of outer loop */
22572209
2258- /*
2259- * Done reading the line. Convert it to server encoding.
2260- */
2210+ /* Done reading the line. Convert it to server encoding. */
22612211if (change_encoding )
22622212{
22632213cvt = (char * )pg_client_to_server ((unsignedchar * )line_buf .data ,
@@ -2457,28 +2407,22 @@ CopyReadAttributeCSV(const char *delim, const char *null_print, char *quote,
24572407break ;
24582408c = line_buf .data [line_buf .cursor ++ ];
24592409
2460- /*
2461- * unquoted field delimiter
2462- */
2410+ /* unquoted field delimiter */
24632411if (!in_quote && c == delimc )
24642412{
24652413* result = NORMAL_ATTR ;
24662414break ;
24672415}
24682416
2469- /*
2470- * start of quoted field (or part of field)
2471- */
2417+ /* start of quoted field (or part of field) */
24722418if (!in_quote && c == quotec )
24732419{
24742420saw_quote = true;
24752421in_quote = true;
24762422continue ;
24772423}
24782424
2479- /*
2480- * escape within a quoted field
2481- */
2425+ /* escape within a quoted field */
24822426if (in_quote && c == escapec )
24832427{
24842428/*