Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb732516

Browse files
committed
Don't produce bogus COPY command when there are no undropped columns
in a table.
1 parent40c4472 commitb732516

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.310 2002/12/01 18:44:00 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.311 2002/12/12 21:03:24 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -827,6 +827,9 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv)
827827
* possibility of retrieving data in the wrong column order. (The
828828
* default column ordering of COPY will not be what we want in certain
829829
* corner cases involving ADD COLUMN and inheritance.)
830+
*
831+
* NB: caller should have already determined that there are dumpable
832+
* columns, so that fmtCopyColumnList will return something.
830833
*/
831834
if (g_fout->remoteVersion >=70300)
832835
column_list=fmtCopyColumnList(tbinfo);
@@ -1140,40 +1143,45 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
11401143

11411144
if (tblinfo[i].dump)
11421145
{
1146+
constchar*column_list;
1147+
11431148
if (g_verbose)
11441149
write_msg(NULL,"preparing to dump the contents of table %s\n",
11451150
classname);
11461151

1147-
dumpCtx= (DumpContext*)malloc(sizeof(DumpContext));
1148-
dumpCtx->tblinfo= (TableInfo*)tblinfo;
1149-
dumpCtx->tblidx=i;
1150-
dumpCtx->oids=oids;
1151-
1152-
if (!dumpData)
1152+
/* Get column list first to check for zero-column table */
1153+
column_list=fmtCopyColumnList(&(tblinfo[i]));
1154+
if (column_list)
11531155
{
1154-
/* Dump/restore using COPY */
1155-
constchar*column_list;
1156-
1157-
dumpFn=dumpClasses_nodumpData;
1158-
column_list=fmtCopyColumnList(&(tblinfo[i]));
1159-
resetPQExpBuffer(copyBuf);
1160-
appendPQExpBuffer(copyBuf,"COPY %s %s %sFROM stdin;\n",
1161-
fmtId(tblinfo[i].relname),
1162-
column_list,
1156+
dumpCtx= (DumpContext*)malloc(sizeof(DumpContext));
1157+
dumpCtx->tblinfo= (TableInfo*)tblinfo;
1158+
dumpCtx->tblidx=i;
1159+
dumpCtx->oids=oids;
1160+
1161+
if (!dumpData)
1162+
{
1163+
/* Dump/restore using COPY */
1164+
dumpFn=dumpClasses_nodumpData;
1165+
resetPQExpBuffer(copyBuf);
1166+
appendPQExpBuffer(copyBuf,"COPY %s %s %sFROM stdin;\n",
1167+
fmtId(tblinfo[i].relname),
1168+
column_list,
11631169
(oids&&tblinfo[i].hasoids) ?"WITH OIDS " :"");
1164-
copyStmt=copyBuf->data;
1165-
}
1166-
else
1167-
{
1168-
/* Restore using INSERT */
1169-
dumpFn=dumpClasses_dumpData;
1170-
copyStmt=NULL;
1171-
}
1170+
copyStmt=copyBuf->data;
1171+
}
1172+
else
1173+
{
1174+
/* Restore using INSERT */
1175+
dumpFn=dumpClasses_dumpData;
1176+
copyStmt=NULL;
1177+
}
11721178

1173-
ArchiveEntry(fout,tblinfo[i].oid,tblinfo[i].relname,
1174-
tblinfo[i].relnamespace->nspname,tblinfo[i].usename,
1175-
"TABLE DATA",NULL,"","",copyStmt,
1176-
dumpFn,dumpCtx);
1179+
ArchiveEntry(fout,tblinfo[i].oid,tblinfo[i].relname,
1180+
tblinfo[i].relnamespace->nspname,
1181+
tblinfo[i].usename,
1182+
"TABLE DATA",NULL,"","",copyStmt,
1183+
dumpFn,dumpCtx);
1184+
}
11771185
}
11781186
}
11791187

@@ -3220,13 +3228,16 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
32203228
if (typdefault)
32213229
appendPQExpBuffer(q," DEFAULT %s",typdefault);
32223230

3223-
/* Fetch and process CHECK Constraints */
3231+
PQclear(res);
3232+
3233+
/*
3234+
* Fetch and process CHECK constraints for the domain
3235+
*/
32243236
appendPQExpBuffer(chkquery,"SELECT conname, consrc "
32253237
"FROM pg_catalog.pg_constraint "
32263238
"WHERE contypid = '%s'::pg_catalog.oid",
32273239
tinfo->oid);
32283240

3229-
PQclear(res);
32303241
res=PQexec(g_conn,chkquery->data);
32313242
if (!res||
32323243
PQresultStatus(res)!=PGRES_TUPLES_OK)
@@ -3236,7 +3247,6 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
32363247
exit_nicely();
32373248
}
32383249

3239-
/* Expecting a single result only */
32403250
ntups=PQntuples(res);
32413251
for (i=0;i<ntups;i++)
32423252
{
@@ -3246,7 +3256,8 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
32463256
conname=PQgetvalue(res,i,PQfnumber(res,"conname"));
32473257
consrc=PQgetvalue(res,i,PQfnumber(res,"consrc"));
32483258

3249-
appendPQExpBuffer(q," CONSTRAINT %s CHECK %s",fmtId(conname),consrc);
3259+
appendPQExpBuffer(q,"\n\tCONSTRAINT %s CHECK %s",
3260+
fmtId(conname),consrc);
32503261
}
32513262

32523263
appendPQExpBuffer(q,";\n");
@@ -6744,7 +6755,10 @@ fmtQualifiedId(const char *schema, const char *id)
67446755
}
67456756

67466757
/*
6747-
* return a column list clause for the given relation.
6758+
* Return a column list clause for the given relation.
6759+
*
6760+
* Special case: if there are no undropped columns in the relation, return
6761+
* NULL, not an invalid "()" column list.
67486762
*/
67496763
staticconstchar*
67506764
fmtCopyColumnList(constTableInfo*ti)
@@ -6772,6 +6786,10 @@ fmtCopyColumnList(const TableInfo *ti)
67726786
appendPQExpBuffer(q,"%s",fmtId(attnames[i]));
67736787
needComma= true;
67746788
}
6789+
6790+
if (!needComma)
6791+
returnNULL;/* no undropped columns */
6792+
67756793
appendPQExpBuffer(q,")");
67766794
returnq->data;
67776795
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp