1212 * by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.320 2003/03/20 05:18:14 momjian Exp $
15+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.321 2003/03/20 06:26:30 momjian Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -2415,6 +2415,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24152415 int i_atttypname ;
24162416 int i_atttypmod ;
24172417 int i_attstattarget ;
2418+ int i_attstorage ;
2419+ int i_typstorage ;
24182420 int i_attnotnull ;
24192421 int i_atthasdef ;
24202422 int i_attisdropped ;
@@ -2459,13 +2461,14 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24592461
24602462 if (g_fout -> remoteVersion >= 70300 )
24612463 {
2462- appendPQExpBuffer (q , "SELECT attnum, attname, atttypmod, attstattarget, "
2463- "attnotnull, atthasdef, attisdropped, attislocal, "
2464- "pg_catalog.format_type(atttypid,atttypmod) as atttypname "
2465- "from pg_catalog.pg_attribute a "
2466- "where attrelid = '%s'::pg_catalog.oid "
2467- "and attnum > 0::pg_catalog.int2 "
2468- "order by attrelid, attnum" ,
2464+ appendPQExpBuffer (q , "SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
2465+ "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
2466+ "pg_catalog.format_type(a.atttypid,a.atttypmod) as atttypname "
2467+ "from pg_catalog.pg_attribute a, pg_catalog.pg_type t "
2468+ "where a.atttypid = t.oid "
2469+ "and a.attrelid = '%s'::pg_catalog.oid "
2470+ "and a.attnum > 0::pg_catalog.int2 "
2471+ "order by a.attrelid, a.attnum" ,
24692472 tbinfo -> oid );
24702473 }
24712474 else if (g_fout -> remoteVersion >= 70100 )
@@ -2475,19 +2478,20 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
24752478 * but we don't dump it because we can't tell whether it's
24762479 * been explicitly set or was just a default.
24772480 */
2478- appendPQExpBuffer (q , "SELECT attnum, attname, atttypmod, -1 as attstattarget, "
2479- "attnotnull, atthasdef, false as attisdropped, null as attislocal, "
2480- "format_type(atttypid,atttypmod) as atttypname "
2481- "from pg_attribute a "
2482- "where attrelid = '%s'::oid "
2483- "and attnum > 0::int2 "
2484- "order by attrelid, attnum" ,
2481+ appendPQExpBuffer (q , "SELECT a.attnum, a.attname, a.atttypmod, -1 as attstattarget, a.attstorage, t.typstorage, "
2482+ "a.attnotnull, a.atthasdef, false as attisdropped, null as attislocal, "
2483+ "format_type(a.atttypid,a.atttypmod) as atttypname "
2484+ "from pg_attribute a, pg_type t "
2485+ "where a.atttypid = t.oid"
2486+ "and a.attrelid = '%s'::oid "
2487+ "and a.attnum > 0::int2 "
2488+ "order by a.attrelid, a.attnum" ,
24852489 tbinfo -> oid );
24862490 }
24872491 else
24882492 {
24892493 /* format_type not available before 7.1 */
2490- appendPQExpBuffer (q , "SELECT attnum, attname, atttypmod, -1 as attstattarget, "
2494+ appendPQExpBuffer (q , "SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage, 'p' as typstorage, "
24912495 "attnotnull, atthasdef, false as attisdropped, null as attislocal, "
24922496 "(select typname from pg_type where oid = atttypid) as atttypname "
24932497 "from pg_attribute a "
@@ -2511,6 +2515,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25112515 i_atttypname = PQfnumber (res , "atttypname" );
25122516 i_atttypmod = PQfnumber (res , "atttypmod" );
25132517 i_attstattarget = PQfnumber (res , "attstattarget" );
2518+ i_attstorage = PQfnumber (res , "attstorage" );
2519+ i_typstorage = PQfnumber (res , "typstorage" );
25142520 i_attnotnull = PQfnumber (res , "attnotnull" );
25152521 i_atthasdef = PQfnumber (res , "atthasdef" );
25162522 i_attisdropped = PQfnumber (res , "attisdropped" );
@@ -2521,6 +2527,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25212527 tbinfo -> atttypnames = (char * * ) malloc (ntups * sizeof (char * ));
25222528 tbinfo -> atttypmod = (int * ) malloc (ntups * sizeof (int ));
25232529 tbinfo -> attstattarget = (int * ) malloc (ntups * sizeof (int ));
2530+ tbinfo -> attstorage = (char * ) malloc (ntups * sizeof (char ));
2531+ tbinfo -> typstorage = (char * ) malloc (ntups * sizeof (char ));
25242532 tbinfo -> attisdropped = (bool * ) malloc (ntups * sizeof (bool ));
25252533 tbinfo -> attislocal = (bool * ) malloc (ntups * sizeof (bool ));
25262534 tbinfo -> attisserial = (bool * ) malloc (ntups * sizeof (bool ));
@@ -2537,6 +2545,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25372545 tbinfo -> atttypnames [j ] = strdup (PQgetvalue (res , j , i_atttypname ));
25382546 tbinfo -> atttypmod [j ] = atoi (PQgetvalue (res , j , i_atttypmod ));
25392547 tbinfo -> attstattarget [j ] = atoi (PQgetvalue (res , j , i_attstattarget ));
2548+ tbinfo -> attstorage [j ] = * (PQgetvalue (res , j , i_attstorage ));
2549+ tbinfo -> typstorage [j ] = * (PQgetvalue (res , j , i_typstorage ));
25402550 tbinfo -> attisdropped [j ] = (PQgetvalue (res , j , i_attisdropped )[0 ] == 't' );
25412551 tbinfo -> attislocal [j ] = (PQgetvalue (res , j , i_attislocal )[0 ] == 't' );
25422552 tbinfo -> attisserial [j ] = false; /* fix below */
@@ -5254,6 +5264,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
52545264 int * parentIndexes ;
52555265 int actual_atts ; /* number of attrs in this CREATE statment */
52565266 char * reltypename ;
5267+ char * storage ;
52575268 char * objoid ;
52585269 const char * ((* commentDeps )[]);
52595270 int j ,
@@ -5566,13 +5577,14 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
55665577
55675578 appendPQExpBuffer (q , ";\n" );
55685579
5569- /*
5570- * Dump per-column statistics information. We only issue an ALTER
5571- * TABLE statement if the attstattarget entry for this column is
5572- * non-negative (i.e. it's not the default value)
5573- */
5580+ /* Loop dumping statistics and storage statements */
55745581 for (j = 0 ; j < tbinfo -> numatts ; j ++ )
55755582 {
5583+ /*
5584+ * Dump per-column statistics information. We only issue an ALTER
5585+ * TABLE statement if the attstattarget entry for this column is
5586+ * non-negative (i.e. it's not the default value)
5587+ */
55765588 if (tbinfo -> attstattarget [j ] >= 0 &&
55775589 !tbinfo -> attisdropped [j ])
55785590 {
@@ -5583,6 +5595,39 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
55835595 appendPQExpBuffer (q , "SET STATISTICS %d;\n" ,
55845596 tbinfo -> attstattarget [j ]);
55855597 }
5598+
5599+ /*
5600+ * Dump per-column storage information. The statement is only dumped if
5601+ * the storage has been changed.
5602+ */
5603+ if (!tbinfo -> attisdropped [j ] && tbinfo -> attstorage [j ] != tbinfo -> typstorage [j ])
5604+ {
5605+ switch (tbinfo -> attstorage [j ]) {
5606+ case 'p' :
5607+ storage = "PLAIN" ;
5608+ break ;
5609+ case 'e' :
5610+ storage = "EXTERNAL" ;
5611+ break ;
5612+ case 'm' :
5613+ storage = "MAIN" ;
5614+ break ;
5615+ case 'x' :
5616+ storage = "EXTENDED" ;
5617+ break ;
5618+ default :
5619+ storage = NULL ;
5620+ }
5621+ /* Only dump the statement if it's a storage type we recognize */
5622+ if (storage != NULL ) {
5623+ appendPQExpBuffer (q , "ALTER TABLE ONLY %s " ,
5624+ fmtId (tbinfo -> relname ));
5625+ appendPQExpBuffer (q , "ALTER COLUMN %s " ,
5626+ fmtId (tbinfo -> attnames [j ]));
5627+ appendPQExpBuffer (q , "SET STORAGE %s;\n" ,
5628+ storage );
5629+ }
5630+ }
55865631 }
55875632 }
55885633
0 commit comments