*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.289 2002/08/22 00:01:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.290 2002/08/22 21:29:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static int dumpBlobs(Archive *AH, char *, void *);
static int dumpDatabase(Archive *AH);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
-static const char* fmtCopyColumnList(const TableInfo* ti);
+static const char *fmtCopyColumnList(const TableInfo *ti);
extern char *optarg;
extern int optind,
*/
selectSourceSchema(tbinfo->relnamespace->nspname);
- column_list = fmtCopyColumnList(tbinfo);
+ /*
+ * If possible, specify the column list explicitly so that we have no
+ * possibility of retrieving data in the wrong column order. (The
+ * default column ordering of COPY will not be what we want in certain
+ * corner cases involving ADD COLUMN and inheritance.)
+ */
+ if (g_fout->remoteVersion >= 70300)
+ column_list = fmtCopyColumnList(tbinfo);
+ else
+ column_list = ""; /* can't select columns in COPY */
if (oids && hasoids)
{
dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
const bool oids)
{
- int i;
+ PQExpBuffer copyBuf = createPQExpBuffer();
DataDumperPtr dumpFn;
DumpContext *dumpCtx;
- char copyBuf[512];
char *copyStmt;
+ int i;
for (i = 0; i < numTables; i++)
{
dumpFn = dumpClasses_nodumpData;
column_list = fmtCopyColumnList(&(tblinfo[i]));
- sprintf(copyBuf, "COPY %s %s %sFROM stdin;\n",
- fmtId(tblinfo[i].relname),
- column_list,
- (oids && tblinfo[i].hasoids) ? "WITH OIDS " : "");
- copyStmt = copyBuf;
+ resetPQExpBuffer(copyBuf);
+ appendPQExpBuffer(copyBuf, "COPY %s %s %sFROM stdin;\n",
+ fmtId(tblinfo[i].relname),
+ column_list,
+ (oids && tblinfo[i].hasoids) ? "WITH OIDS " : "");
+ copyStmt = copyBuf->data;
}
else
{
dumpFn, dumpCtx);
}
}
+
+ destroyPQExpBuffer(copyBuf);
}
/*
* return a column list clause for the given relation.
- * returns an empty string if the remote server is older than
- * 7.3.
*/
-static const char*
-fmtCopyColumnList(const TableInfo* ti)
+static const char *
+fmtCopyColumnList(const TableInfo *ti)
{
static PQExpBuffer q = NULL;
int numatts = ti->numatts;
bool needComma;
int i;
- if (g_fout->remoteVersion < 70300)
- return "";
-
if (q) /* first time through? */
resetPQExpBuffer(q);
else
q = createPQExpBuffer();
- resetPQExpBuffer(q);
-
appendPQExpBuffer(q, "(");
needComma = false;
for (i = 0; i < numatts; i++)