1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.326 2003/04/04 20:42:12 momjian Exp $
15+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.327 2003/04/25 02:28:22 tgl Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -838,9 +838,6 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv)
838838 * possibility of retrieving data in the wrong column order. (The
839839 * default column ordering of COPY will not be what we want in certain
840840 * corner cases involving ADD COLUMN and inheritance.)
841- *
842- * NB: caller should have already determined that there are dumpable
843- * columns, so that fmtCopyColumnList will return something.
844841 */
845842if (g_fout -> remoteVersion >=70300 )
846843column_list = fmtCopyColumnList (tbinfo );
@@ -975,6 +972,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
975972PQExpBuffer q = createPQExpBuffer ();
976973PGresult * res ;
977974int tuple ;
975+ int nfields ;
978976int field ;
979977
980978/*
@@ -1024,14 +1022,21 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
10241022exit_nicely ();
10251023}
10261024
1025+ nfields = PQnfields (res );
10271026for (tuple = 0 ;tuple < PQntuples (res );tuple ++ )
10281027{
10291028archprintf (fout ,"INSERT INTO %s " ,fmtId (classname ));
1029+ if (nfields == 0 )
1030+ {
1031+ /* corner case for zero-column table */
1032+ archprintf (fout ,"DEFAULT VALUES;\n" );
1033+ continue ;
1034+ }
10301035if (attrNames == true)
10311036{
10321037resetPQExpBuffer (q );
10331038appendPQExpBuffer (q ,"(" );
1034- for (field = 0 ;field < PQnfields ( res ) ;field ++ )
1039+ for (field = 0 ;field < nfields ;field ++ )
10351040{
10361041if (field > 0 )
10371042appendPQExpBuffer (q ,", " );
@@ -1041,7 +1046,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
10411046archprintf (fout ,"%s" ,q -> data );
10421047}
10431048archprintf (fout ,"VALUES (" );
1044- for (field = 0 ;field < PQnfields ( res ) ;field ++ )
1049+ for (field = 0 ;field < nfields ;field ++ )
10451050{
10461051if (field > 0 )
10471052archprintf (fout ,", " );
@@ -1154,45 +1159,38 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
11541159
11551160if (tblinfo [i ].dump )
11561161{
1157- const char * column_list ;
1158-
11591162if (g_verbose )
11601163write_msg (NULL ,"preparing to dump the contents of table %s\n" ,
11611164classname );
11621165
1163- /* Get column list first to check for zero-column table */
1164- column_list = fmtCopyColumnList (& (tblinfo [i ]));
1165- if (column_list )
1166- {
1167- dumpCtx = (DumpContext * )malloc (sizeof (DumpContext ));
1168- dumpCtx -> tblinfo = (TableInfo * )tblinfo ;
1169- dumpCtx -> tblidx = i ;
1170- dumpCtx -> oids = oids ;
1166+ dumpCtx = (DumpContext * )malloc (sizeof (DumpContext ));
1167+ dumpCtx -> tblinfo = (TableInfo * )tblinfo ;
1168+ dumpCtx -> tblidx = i ;
1169+ dumpCtx -> oids = oids ;
11711170
1172- if (!dumpData )
1173- {
1174- /* Dump/restore using COPY */
1175- dumpFn = dumpClasses_nodumpData ;
1176- resetPQExpBuffer (copyBuf );
1177- appendPQExpBuffer (copyBuf ,"COPY %s %s %sFROM stdin;\n" ,
1178- fmtId (tblinfo [i ].relname ),
1179- column_list ,
1171+ if (!dumpData )
1172+ {
1173+ /* Dump/restore using COPY */
1174+ dumpFn = dumpClasses_nodumpData ;
1175+ resetPQExpBuffer (copyBuf );
1176+ appendPQExpBuffer (copyBuf ,"COPY %s %s %sFROM stdin;\n" ,
1177+ fmtId (tblinfo [i ].relname ),
1178+ fmtCopyColumnList ( & ( tblinfo [ i ])) ,
11801179 (oids && tblinfo [i ].hasoids ) ?"WITH OIDS " :"" );
1181- copyStmt = copyBuf -> data ;
1182- }
1183- else
1184- {
1185- /* Restore using INSERT */
1186- dumpFn = dumpClasses_dumpData ;
1187- copyStmt = NULL ;
1188- }
1189-
1190- ArchiveEntry (fout ,tblinfo [i ].oid ,tblinfo [i ].relname ,
1191- tblinfo [i ].relnamespace -> nspname ,
1192- tblinfo [i ].usename ,
1193- "TABLE DATA" ,NULL ,"" ,"" ,copyStmt ,
1194- dumpFn ,dumpCtx );
1180+ copyStmt = copyBuf -> data ;
11951181}
1182+ else
1183+ {
1184+ /* Restore using INSERT */
1185+ dumpFn = dumpClasses_dumpData ;
1186+ copyStmt = NULL ;
1187+ }
1188+
1189+ ArchiveEntry (fout ,tblinfo [i ].oid ,tblinfo [i ].relname ,
1190+ tblinfo [i ].relnamespace -> nspname ,
1191+ tblinfo [i ].usename ,
1192+ "TABLE DATA" ,NULL ,"" ,"" ,copyStmt ,
1193+ dumpFn ,dumpCtx );
11961194}
11971195}
11981196
@@ -6980,7 +6978,7 @@ fmtQualifiedId(const char *schema, const char *id)
69806978 * Return a column list clause for the given relation.
69816979 *
69826980 * Special case: if there are no undropped columns in the relation, return
6983- *NULL , not an invalid "()" column list.
6981+ *"" , not an invalid "()" column list.
69846982 */
69856983static const char *
69866984fmtCopyColumnList (const TableInfo * ti )
@@ -7010,7 +7008,7 @@ fmtCopyColumnList(const TableInfo *ti)
70107008}
70117009
70127010if (!needComma )
7013- return NULL ; /* no undropped columns */
7011+ return "" ; /* no undropped columns */
70147012
70157013appendPQExpBuffer (q ,")" );
70167014return q -> data ;