66 *
77 *
88 * IDENTIFICATION
9- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.40 1998/01/31 04:38:18 momjian Exp $
9+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.41 1998/02/10 16:02:51 momjian Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -65,7 +65,7 @@ static void CopyAttributeOut(FILE *fp, char *string, char *delim);
6565static int CountTuples (Relation relation );
6666
6767extern FILE * Pfout ,
68- * Pfin ;
68+ * Pfin ;
6969
7070static int lineno ;
7171
@@ -205,6 +205,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
205205FmgrInfo * out_functions ;
206206Oid out_func_oid ;
207207Oid * elements ;
208+ int16 * typmod ;
208209Datum value ;
209210bool isnull ;/* The attribute we are copying is null */
210211char * nulls ;
@@ -230,18 +231,21 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
230231{
231232out_functions = (FmgrInfo * )palloc (attr_count * sizeof (FmgrInfo ));
232233elements = (Oid * )palloc (attr_count * sizeof (Oid ));
234+ typmod = (int16 * )palloc (attr_count * sizeof (int16 ));
233235for (i = 0 ;i < attr_count ;i ++ )
234236{
235237out_func_oid = (Oid )GetOutputFunction (attr [i ]-> atttypid );
236238fmgr_info (out_func_oid ,& out_functions [i ]);
237239elements [i ]= GetTypeElement (attr [i ]-> atttypid );
240+ typmod [i ]= attr [i ]-> atttypmod ;
238241}
239242nulls = NULL ;/* meaningless, but compiler doesn't know
240243 * that */
241244}
242245else
243246{
244247elements = NULL ;
248+ typmod = NULL ;
245249out_functions = NULL ;
246250nulls = (char * )palloc (attr_count );
247251for (i = 0 ;i < attr_count ;i ++ )
@@ -271,7 +275,8 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
271275{
272276if (!isnull )
273277{
274- string = (char * ) (* fmgr_faddr (& out_functions [i ])) (value ,elements [i ]);
278+ string = (char * ) (* fmgr_faddr (& out_functions [i ]))
279+ (value ,elements [i ],typmod [i ]);
275280CopyAttributeOut (fp ,string ,delim );
276281pfree (string );
277282}
@@ -345,6 +350,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
345350{
346351pfree (out_functions );
347352pfree (elements );
353+ pfree (typmod );
348354}
349355
350356heap_close (rel );
@@ -376,6 +382,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
376382tuples_read = 0 ;
377383bool reading_to_eof = true;
378384Oid * elements ;
385+ int16 * typmod ;
379386FuncIndexInfo * finfo ,
380387* * finfoP = NULL ;
381388TupleDesc * itupdescArr ;
@@ -498,17 +505,20 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
498505{
499506in_functions = (FmgrInfo * )palloc (attr_count * sizeof (FmgrInfo ));
500507elements = (Oid * )palloc (attr_count * sizeof (Oid ));
508+ typmod = (int16 * )palloc (attr_count * sizeof (int16 ));
501509for (i = 0 ;i < attr_count ;i ++ )
502510{
503511in_func_oid = (Oid )GetInputFunction (attr [i ]-> atttypid );
504512fmgr_info (in_func_oid ,& in_functions [i ]);
505513elements [i ]= GetTypeElement (attr [i ]-> atttypid );
514+ typmod [i ]= attr [i ]-> atttypmod ;
506515}
507516}
508517else
509518{
510519in_functions = NULL ;
511520elements = NULL ;
521+ typmod = NULL ;
512522fread (& ntuples ,sizeof (int32 ),1 ,fp );
513523if (ntuples != 0 )
514524reading_to_eof = false;
@@ -574,7 +584,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
574584values [i ]=
575585(Datum ) (* fmgr_faddr (& in_functions [i ])) (string ,
576586elements [i ],
577- attr [i ]-> atttypmod );
587+ typmod [i ]);
578588
579589/*
580590 * Sanity check - by reference attributes cannot
@@ -801,9 +811,13 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
801811done = true;
802812}
803813pfree (values );
814+ pfree (nulls );
804815if (!binary )
816+ {
805817pfree (in_functions );
806- pfree (nulls );
818+ pfree (elements );
819+ pfree (typmod );
820+ }
807821pfree (byval );
808822heap_close (rel );
809823}