1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.337 2003/07/2519:37:21 momjian Exp $
15+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.338 2003/07/2521:02:52 tgl Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -2371,6 +2371,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
23712371j ,
23722372k ;
23732373PQExpBuffer q = createPQExpBuffer ();
2374+ int i_attnum ;
23742375int i_attname ;
23752376int i_atttypname ;
23762377int i_atttypmod ;
@@ -2421,12 +2422,13 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24212422
24222423if (g_fout -> remoteVersion >=70300 )
24232424{
2425+ /* need left join here to not fail on dropped columns ... */
24242426appendPQExpBuffer (q ,"SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
2425- "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
2426- "pg_catalog.format_type(a.atttypid ,a.atttypmod) as atttypname "
2427- "from pg_catalog.pg_attribute a, pg_catalog.pg_type t "
2428- "where a.atttypid = t.oid "
2429- "and a.attrelid = '%s'::pg_catalog.oid "
2427+ "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
2428+ "pg_catalog.format_type(t.oid ,a.atttypmod) as atttypname "
2429+ "from pg_catalog.pg_attribute a left join pg_catalog.pg_type t "
2430+ "on a.atttypid = t.oid "
2431+ "where a.attrelid = '%s'::pg_catalog.oid "
24302432"and a.attnum > 0::pg_catalog.int2 "
24312433"order by a.attrelid, a.attnum" ,
24322434tbinfo -> oid );
@@ -2439,19 +2441,19 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24392441 * been explicitly set or was just a default.
24402442 */
24412443appendPQExpBuffer (q ,"SELECT a.attnum, a.attname, a.atttypmod, -1 as attstattarget, a.attstorage, t.typstorage, "
2442- "a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
2443- "format_type(a.atttypid ,a.atttypmod) as atttypname "
2444- "from pg_attribute a, pg_type t "
2445- "where a.atttypid = t.oid "
2446- "and a.attrelid = '%s'::oid "
2444+ "a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
2445+ "format_type(t.oid ,a.atttypmod) as atttypname "
2446+ "from pg_attribute a left join pg_type t "
2447+ "on a.atttypid = t.oid "
2448+ "where a.attrelid = '%s'::oid "
24472449"and a.attnum > 0::int2 "
24482450"order by a.attrelid, a.attnum" ,
24492451tbinfo -> oid );
24502452}
24512453else
24522454{
24532455/* format_type not available before 7.1 */
2454- appendPQExpBuffer (q ,"SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage,'p' as typstorage, "
2456+ appendPQExpBuffer (q ,"SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage,attstorage as typstorage, "
24552457"attnotnull, atthasdef, false as attisdropped, null as attislocal, "
24562458"(select typname from pg_type where oid = atttypid) as atttypname "
24572459"from pg_attribute a "
@@ -2471,6 +2473,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24712473
24722474ntups = PQntuples (res );
24732475
2476+ i_attnum = PQfnumber (res ,"attnum" );
24742477i_attname = PQfnumber (res ,"attname" );
24752478i_atttypname = PQfnumber (res ,"atttypname" );
24762479i_atttypmod = PQfnumber (res ,"atttypmod" );
@@ -2501,6 +2504,12 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25012504
25022505for (j = 0 ;j < ntups ;j ++ )
25032506{
2507+ if (j + 1 != atoi (PQgetvalue (res ,j ,i_attnum )))
2508+ {
2509+ write_msg (NULL ,"invalid attribute numbering in table \"%s\"\n" ,
2510+ tbinfo -> relname );
2511+ exit_nicely ();
2512+ }
25042513tbinfo -> attnames [j ]= strdup (PQgetvalue (res ,j ,i_attname ));
25052514tbinfo -> atttypnames [j ]= strdup (PQgetvalue (res ,j ,i_atttypname ));
25062515tbinfo -> atttypmod [j ]= atoi (PQgetvalue (res ,j ,i_atttypmod ));
@@ -5410,7 +5419,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
54105419
54115420/*
54125421 * Dump per-column storage information. The statement is only dumped if
5413- * the storage has been changed.
5422+ * the storage has been changed from the type's default .
54145423 */
54155424if (!tbinfo -> attisdropped [j ]&& tbinfo -> attstorage [j ]!= tbinfo -> typstorage [j ])
54165425{