Index: src/backend/commands/copy.c =================================================================== RCS file: /var/cvsup/pgsql/src/backend/commands/copy.c,v retrieving revision 1.144 diff -c -r1.144 copy.c *** src/backend/commands/copy.c 4 Dec 2001 21:19:57 -0000 1.144 --- src/backend/commands/copy.c 13 Jan 2002 15:18:06 -0000 *************** *** 45,52 **** /* non-export function prototypes */ ! static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print); ! static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print); static Oid GetInputFunction(Oid type); static Oid GetTypeElement(Oid type); static void CopyReadNewline(FILE *fp, int *newline); --- 45,52 ---- /* non-export function prototypes */ ! static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print,List *attlist); ! static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print,List *attlist); static Oid GetInputFunction(Oid type); static Oid GetTypeElement(Oid type); static void CopyReadNewline(FILE *fp, int *newline); *************** *** 261,267 **** */ void DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ! char *filename, char *delim, char *null_print) { FILE *fp; Relation rel; --- 261,267 ---- */ void DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ! char *filename, char *delim, char *null_print, List* attlist) { FILE *fp; Relation rel; *************** *** 333,339 **** "reading. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); } ! CopyFrom(rel, binary, oids, fp, delim, null_print); } else { /* copy from database to file */ --- 333,339 ---- "reading. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); } ! CopyFrom(rel, binary, oids, fp, delim, null_print, attlist); } else { /* copy from database to file */ *************** *** 379,385 **** "writing. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); } ! CopyTo(rel, binary, oids, fp, delim, null_print); } if (!pipe) --- 379,385 ---- "writing. Errno = %s (%d).", (int) geteuid(), filename, strerror(errno), errno); } ! CopyTo(rel, binary, oids, fp, delim, null_print, attlist); } if (!pipe) *************** *** 408,414 **** */ static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, ! char *delim, char *null_print) { HeapTuple tuple; TupleDesc tupDesc; --- 408,414 ---- */ static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, ! char *delim, char *null_print, List* attlist) { HeapTuple tuple; TupleDesc tupDesc; *************** *** 620,626 **** */ static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, ! char *delim, char *null_print) { HeapTuple tuple; TupleDesc tupDesc; --- 620,626 ---- */ static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, ! char *delim, char *null_print, List* attlist) { HeapTuple tuple; TupleDesc tupDesc; *************** *** 644,651 **** bool file_has_oids; tupDesc = RelationGetDescr(rel); ! attr = tupDesc->attrs; ! attr_count = tupDesc->natts; /* * We need a ResultRelInfo so we can use the regular executor's --- 644,672 ---- bool file_has_oids; tupDesc = RelationGetDescr(rel); ! attr_count = tupDesc->natts; ! if( attlist ) ! { ! int i,c; ! List* cur; ! c = 0; ! attr = (Form_pg_attribute*)palloc(sizeof(Form_pg_attribute*) * attr_count); ! foreach(cur,attlist) ! { ! char* col = ((Ident*)lfirst(cur))->name; ! for(i=0;iattrs[i]->attname)) == 0) ! { ! attr[c] = tupDesc->attrs[i]; ! ++c; ! } ! } ! if( c != attr_count ) ! elog(ERROR,"Columns specified in COPY FROM command do not match columns in target table."); ! } ! else{ ! attr = tupDesc->attrs; ! } /* * We need a ResultRelInfo so we can use the regular executor's *************** *** 953,958 **** --- 974,981 ---- pfree(in_functions); pfree(elements); } + if( attlist ) + pfree(attr); ExecDropTupleTable(tupleTable, true); Index: src/backend/parser/gram.y =================================================================== RCS file: /var/cvsup/pgsql/src/backend/parser/gram.y,v retrieving revision 2.276 diff -c -r2.276 gram.y *** src/backend/parser/gram.y 9 Dec 2001 04:39:39 -0000 2.276 --- src/backend/parser/gram.y 13 Jan 2002 14:56:43 -0000 *************** *** 1193,1203 **** --- 1193,1217 ---- CopyStmt *n = makeNode(CopyStmt); n->binary = $2; n->relname = $3; + n->attlist = NIL; n->oids = $4; n->direction = $5; n->filename = $6; n->delimiter = $7; n->null_print = $8; + $$ = (Node *)n; + } + | COPY opt_binary relation_name opt_column_list opt_with_copy copy_dirn copy_file_name copy_delimiter copy_null + { + CopyStmt *n = makeNode(CopyStmt); + n->binary = $2; + n->relname = $3; + n->attlist = $4; + n->oids = $5; + n->direction = $6; + n->filename = $7; + n->delimiter = $8; + n->null_print = $9; $$ = (Node *)n; } ; Index: src/backend/tcop/utility.c =================================================================== RCS file: /var/cvsup/pgsql/src/backend/tcop/utility.c,v retrieving revision 1.124 diff -c -r1.124 utility.c *** src/backend/tcop/utility.c 3 Jan 2002 23:21:32 -0000 1.124 --- src/backend/tcop/utility.c 13 Jan 2002 13:42:56 -0000 *************** *** 354,360 **** */ stmt->filename, stmt->delimiter, ! stmt->null_print); } break; --- 354,361 ---- */ stmt->filename, stmt->delimiter, ! stmt->null_print, ! stmt->attlist); } break; Index: src/include/commands/copy.h =================================================================== RCS file: /var/cvsup/pgsql/src/include/commands/copy.h,v retrieving revision 1.16 diff -c -r1.16 copy.h *** src/include/commands/copy.h 5 Nov 2001 17:46:33 -0000 1.16 --- src/include/commands/copy.h 13 Jan 2002 13:52:56 -0000 *************** *** 14,22 **** #ifndef COPY_H #define COPY_H extern int copy_lineno; void DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ! char *filename, char *delim, char *null_print); #endif /* COPY_H */ --- 14,24 ---- #ifndef COPY_H #define COPY_H + #include "utils/portal.h" + extern int copy_lineno; void DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ! char *filename, char *delim, char *null_print, List* _al); #endif /* COPY_H */ Index: src/include/nodes/parsenodes.h =================================================================== RCS file: /var/cvsup/pgsql/src/include/nodes/parsenodes.h,v retrieving revision 1.151 diff -c -r1.151 parsenodes.h *** src/include/nodes/parsenodes.h 5 Nov 2001 17:46:34 -0000 1.151 --- src/include/nodes/parsenodes.h 13 Jan 2002 13:40:22 -0000 *************** *** 183,188 **** --- 183,189 ---- char *filename; /* if NULL, use stdin/stdout */ char *delimiter; /* delimiter character, \t by default */ char *null_print; /* how to print NULLs, `\N' by default */ + List *attlist; /* list of attributes */ } CopyStmt; /* ----------------------