22
22
*
23
23
*
24
24
* IDENTIFICATION
25
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.289 2002/08/22 00:01:45 tgl Exp $
25
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.290 2002/08/22 21:29:34 tgl Exp $
26
26
*
27
27
*-------------------------------------------------------------------------
28
28
*/
@@ -124,7 +124,7 @@ static char *GetPrivileges(Archive *AH, const char *s, const char *type);
124
124
static int dumpBlobs (Archive * AH , char * , void * );
125
125
static int dumpDatabase (Archive * AH );
126
126
static const char * getAttrName (int attrnum , TableInfo * tblInfo );
127
- static const char * fmtCopyColumnList (const TableInfo * ti );
127
+ static const char * fmtCopyColumnList (const TableInfo * ti );
128
128
129
129
extern char * optarg ;
130
130
extern int optind ,
@@ -828,7 +828,16 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv)
828
828
*/
829
829
selectSourceSchema (tbinfo -> relnamespace -> nspname );
830
830
831
- column_list = fmtCopyColumnList (tbinfo );
831
+ /*
832
+ * If possible, specify the column list explicitly so that we have no
833
+ * possibility of retrieving data in the wrong column order. (The
834
+ * default column ordering of COPY will not be what we want in certain
835
+ * corner cases involving ADD COLUMN and inheritance.)
836
+ */
837
+ if (g_fout -> remoteVersion >= 70300 )
838
+ column_list = fmtCopyColumnList (tbinfo );
839
+ else
840
+ column_list = "" ; /* can't select columns in COPY */
832
841
833
842
if (oids && hasoids )
834
843
{
@@ -1123,11 +1132,11 @@ static void
1123
1132
dumpClasses (const TableInfo * tblinfo , const int numTables , Archive * fout ,
1124
1133
const bool oids )
1125
1134
{
1126
- int i ;
1135
+ PQExpBuffer copyBuf = createPQExpBuffer () ;
1127
1136
DataDumperPtr dumpFn ;
1128
1137
DumpContext * dumpCtx ;
1129
- char copyBuf [512 ];
1130
1138
char * copyStmt ;
1139
+ int i ;
1131
1140
1132
1141
for (i = 0 ; i < numTables ; i ++ )
1133
1142
{
@@ -1162,11 +1171,12 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
1162
1171
1163
1172
dumpFn = dumpClasses_nodumpData ;
1164
1173
column_list = fmtCopyColumnList (& (tblinfo [i ]));
1165
- sprintf (copyBuf , "COPY %s %s %sFROM stdin;\n" ,
1166
- fmtId (tblinfo [i ].relname ),
1167
- column_list ,
1168
- (oids && tblinfo [i ].hasoids ) ? "WITH OIDS " : "" );
1169
- copyStmt = copyBuf ;
1174
+ resetPQExpBuffer (copyBuf );
1175
+ appendPQExpBuffer (copyBuf , "COPY %s %s %sFROM stdin;\n" ,
1176
+ fmtId (tblinfo [i ].relname ),
1177
+ column_list ,
1178
+ (oids && tblinfo [i ].hasoids ) ? "WITH OIDS " : "" );
1179
+ copyStmt = copyBuf -> data ;
1170
1180
}
1171
1181
else
1172
1182
{
@@ -1181,6 +1191,8 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
1181
1191
dumpFn , dumpCtx );
1182
1192
}
1183
1193
}
1194
+
1195
+ destroyPQExpBuffer (copyBuf );
1184
1196
}
1185
1197
1186
1198
@@ -6652,11 +6664,9 @@ fmtQualifiedId(const char *schema, const char *id)
6652
6664
6653
6665
/*
6654
6666
* return a column list clause for the given relation.
6655
- * returns an empty string if the remote server is older than
6656
- * 7.3.
6657
6667
*/
6658
- static const char *
6659
- fmtCopyColumnList (const TableInfo * ti )
6668
+ static const char *
6669
+ fmtCopyColumnList (const TableInfo * ti )
6660
6670
{
6661
6671
static PQExpBuffer q = NULL ;
6662
6672
int numatts = ti -> numatts ;
@@ -6665,16 +6675,11 @@ fmtCopyColumnList(const TableInfo* ti)
6665
6675
bool needComma ;
6666
6676
int i ;
6667
6677
6668
- if (g_fout -> remoteVersion < 70300 )
6669
- return "" ;
6670
-
6671
6678
if (q ) /* first time through? */
6672
6679
resetPQExpBuffer (q );
6673
6680
else
6674
6681
q = createPQExpBuffer ();
6675
6682
6676
- resetPQExpBuffer (q );
6677
-
6678
6683
appendPQExpBuffer (q , "(" );
6679
6684
needComma = false;
6680
6685
for (i = 0 ; i < numatts ; i ++ )
0 commit comments