3
3
*
4
4
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
5
5
*
6
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.116 2005/06/14 02:57:41 momjian Exp $
6
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.117 2005/06/14 23:59:31 momjian Exp $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "describe.h"
@@ -37,8 +37,8 @@ static void processNamePattern(PQExpBuffer buf, const char *pattern,
37
37
const char * schemavar , const char * namevar ,
38
38
const char * altnamevar , const char * visibilityrule );
39
39
40
- static void add_tablespace_footer (char relkind , Oid tablespace ,
41
- char * * footers , int * count , PQExpBufferData buf );
40
+ static bool add_tablespace_footer (char relkind , Oid tablespace , char * * footers ,
41
+ int * count , PQExpBufferData buf , bool newline );
42
42
43
43
/*----------------
44
44
* Handlers for various slash commands displaying some sort of list
@@ -942,7 +942,7 @@ describeOneTableDetails(const char *schemaname,
942
942
footers = pg_malloc_zero (4 * sizeof (* footers ));
943
943
footers [count_footers ++ ] = pg_strdup (tmpbuf .data );
944
944
add_tablespace_footer (tableinfo .relkind , tableinfo .tablespace ,
945
- footers , & count_footers , tmpbuf );
945
+ footers , & count_footers , tmpbuf , true );
946
946
footers [count_footers ] = NULL ;
947
947
948
948
}
@@ -1022,7 +1022,7 @@ describeOneTableDetails(const char *schemaname,
1022
1022
{
1023
1023
printfPQExpBuffer (& buf ,
1024
1024
"SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "
1025
- "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n"
1025
+ "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace \n"
1026
1026
"FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
1027
1027
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
1028
1028
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname" ,
@@ -1142,6 +1142,7 @@ describeOneTableDetails(const char *schemaname,
1142
1142
{
1143
1143
const char * indexdef ;
1144
1144
const char * usingpos ;
1145
+ PQExpBufferData tmpbuf ;
1145
1146
1146
1147
/* Output index name */
1147
1148
printfPQExpBuffer (& buf , _ (" \"%s\"" ),
@@ -1165,6 +1166,22 @@ describeOneTableDetails(const char *schemaname,
1165
1166
if (strcmp (PQgetvalue (result1 , i , 3 ), "t" ) == 0 )
1166
1167
appendPQExpBuffer (& buf , " CLUSTER" );
1167
1168
1169
+ /* Print tablespace of the index on the same line */
1170
+ count_footers += 1 ;
1171
+ initPQExpBuffer (& tmpbuf );
1172
+ if (add_tablespace_footer ('i' ,
1173
+ atooid (PQgetvalue (result1 , i , 5 )),
1174
+ footers , & count_footers , tmpbuf , false))
1175
+ {
1176
+ appendPQExpBuffer (& buf , ", " );
1177
+ appendPQExpBuffer (& buf , tmpbuf .data );
1178
+
1179
+ count_footers -= 2 ;
1180
+ }
1181
+ else
1182
+ count_footers -= 1 ;
1183
+ termPQExpBuffer (& tmpbuf );
1184
+
1168
1185
footers [count_footers ++ ] = pg_strdup (buf .data );
1169
1186
}
1170
1187
}
@@ -1265,7 +1282,7 @@ describeOneTableDetails(const char *schemaname,
1265
1282
}
1266
1283
1267
1284
add_tablespace_footer (tableinfo .relkind , tableinfo .tablespace ,
1268
- footers , & count_footers , buf );
1285
+ footers , & count_footers , buf , true );
1269
1286
/* end of list marker */
1270
1287
footers [count_footers ] = NULL ;
1271
1288
@@ -1317,9 +1334,13 @@ describeOneTableDetails(const char *schemaname,
1317
1334
}
1318
1335
1319
1336
1320
- static void
1337
+ /*
1338
+ * Return true if the relation uses non default tablespace;
1339
+ * otherwise return false
1340
+ */
1341
+ static bool
1321
1342
add_tablespace_footer (char relkind , Oid tablespace , char * * footers ,
1322
- int * count , PQExpBufferData buf )
1343
+ int * count , PQExpBufferData buf , bool newline )
1323
1344
{
1324
1345
/* relkinds for which we support tablespaces */
1325
1346
if (relkind == 'r' || relkind == 'i' )
@@ -1336,17 +1357,23 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
1336
1357
"WHERE oid = '%u';" , tablespace );
1337
1358
result1 = PSQLexec (buf .data , false);
1338
1359
if (!result1 )
1339
- return ;
1360
+ return false ;
1340
1361
/* Should always be the case, but.... */
1341
1362
if (PQntuples (result1 ) > 0 )
1342
1363
{
1343
- printfPQExpBuffer (& buf , _ ("Tablespace: \"%s\"" ),
1344
- PQgetvalue (result1 , 0 , 0 ));
1364
+ printfPQExpBuffer (& buf ,
1365
+ newline ?_ ("Tablespace: \"%s\"" ):_ ("tablespace \"%s\"" ),
1366
+ PQgetvalue (result1 , 0 , 0 ));
1367
+
1345
1368
footers [(* count )++ ] = pg_strdup (buf .data );
1346
1369
}
1347
1370
PQclear (result1 );
1371
+
1372
+ return true;
1348
1373
}
1349
1374
}
1375
+
1376
+ return false;
1350
1377
}
1351
1378
1352
1379
/*
0 commit comments