12
12
*by PostgreSQL
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.388 2004/10/06 23:31:45 neilc Exp $
15
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.389 2004/10/18 00:20:41 tgl Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -108,6 +108,9 @@ static const CatalogId nilCatalogId = {0, 0};
108
108
static NamespaceInfo * g_namespaces ;
109
109
static int g_numNamespaces ;
110
110
111
+ /* need the name of the database's default tablespace */
112
+ static char * dbDefaultTableSpace ;
113
+
111
114
/* flag to turn on/off dollar quoting */
112
115
static int disable_dollar_quoting = 0 ;
113
116
@@ -1249,6 +1252,9 @@ dumpDatabase(Archive *AH)
1249
1252
encoding = PQgetvalue (res ,0 ,i_encoding );
1250
1253
tablespace = PQgetvalue (res ,0 ,i_tablespace );
1251
1254
1255
+ /* save dattablespace name for later dump routines */
1256
+ dbDefaultTableSpace = strdup (tablespace );
1257
+
1252
1258
appendPQExpBuffer (creaQry ,"CREATE DATABASE %s WITH TEMPLATE = template0" ,
1253
1259
fmtId (datname ));
1254
1260
if (strlen (encoding )> 0 )
@@ -1257,7 +1263,8 @@ dumpDatabase(Archive *AH)
1257
1263
appendStringLiteral (creaQry ,encoding , true);
1258
1264
}
1259
1265
if (strlen (tablespace )> 0 && strcmp (tablespace ,"pg_default" )!= 0 )
1260
- appendPQExpBuffer (creaQry ," TABLESPACE = %s" ,fmtId (tablespace ));
1266
+ appendPQExpBuffer (creaQry ," TABLESPACE = %s" ,
1267
+ fmtId (tablespace ));
1261
1268
appendPQExpBuffer (creaQry ,";\n" );
1262
1269
1263
1270
appendPQExpBuffer (delQry ,"DROP DATABASE %s;\n" ,
@@ -4428,7 +4435,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
4428
4435
appendPQExpBuffer (q ,"CREATE SCHEMA %s AUTHORIZATION %s" ,
4429
4436
qnspname ,fmtId (nspinfo -> usename ));
4430
4437
4431
- /* Add tablespace qualifier, if not default */
4438
+ /* Add tablespace qualifier, if not defaultfor database */
4432
4439
if (strlen (nspinfo -> nsptablespace )!= 0 )
4433
4440
appendPQExpBuffer (q ," TABLESPACE %s" ,
4434
4441
fmtId (nspinfo -> nsptablespace ));
@@ -6652,13 +6659,16 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
6652
6659
appendPQExpBuffer (q ,")" );
6653
6660
}
6654
6661
6655
- /* Output tablespace clause if necessary */
6656
- if (strlen (tbinfo -> reltablespace )!= 0 &&
6657
- strcmp (tbinfo -> reltablespace ,
6662
+ /* Output tablespace clause if different from parent schema's */
6663
+ if (strcmp (tbinfo -> reltablespace ,
6658
6664
tbinfo -> dobj .namespace -> nsptablespace )!= 0 )
6659
6665
{
6660
- appendPQExpBuffer (q ," TABLESPACE %s" ,
6661
- fmtId (tbinfo -> reltablespace ));
6666
+ if (strlen (tbinfo -> reltablespace )!= 0 )
6667
+ appendPQExpBuffer (q ," TABLESPACE %s" ,
6668
+ fmtId (tbinfo -> reltablespace ));
6669
+ else if (strlen (dbDefaultTableSpace )!= 0 )
6670
+ appendPQExpBuffer (q ," TABLESPACE %s" ,
6671
+ fmtId (dbDefaultTableSpace ));
6662
6672
}
6663
6673
6664
6674
appendPQExpBuffer (q ,";\n" );
@@ -6947,13 +6957,16 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
6947
6957
6948
6958
appendPQExpBuffer (q ,")" );
6949
6959
6950
- /* Output tablespace clause if necessary */
6951
- if (strlen (indxinfo -> tablespace )!= 0 &&
6952
- strcmp (indxinfo -> tablespace ,
6960
+ /* Output tablespace clause if different from parent table's */
6961
+ if (strcmp (indxinfo -> tablespace ,
6953
6962
indxinfo -> indextable -> reltablespace )!= 0 )
6954
6963
{
6955
- appendPQExpBuffer (q ," USING INDEX TABLESPACE %s" ,
6956
- fmtId (indxinfo -> tablespace ));
6964
+ if (strlen (indxinfo -> tablespace )!= 0 )
6965
+ appendPQExpBuffer (q ," USING INDEX TABLESPACE %s" ,
6966
+ fmtId (indxinfo -> tablespace ));
6967
+ else if (strlen (dbDefaultTableSpace )!= 0 )
6968
+ appendPQExpBuffer (q ," USING INDEX TABLESPACE %s" ,
6969
+ fmtId (dbDefaultTableSpace ));
6957
6970
}
6958
6971
6959
6972
appendPQExpBuffer (q ,";\n" );