8
8
*
9
9
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
10
10
*
11
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.220 2009/07/06 17:01:42 petere Exp $
11
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.221 2009/07/07 16:28:38 tgl Exp $
12
12
*/
13
13
#include "postgres_fe.h"
14
14
@@ -1028,7 +1028,7 @@ describeOneTableDetails(const char *schemaname,
1028
1028
char * * ptr ;
1029
1029
PQExpBufferData title ;
1030
1030
PQExpBufferData tmpbuf ;
1031
- int cols = 0 ;
1031
+ int cols ;
1032
1032
int numrows = 0 ;
1033
1033
struct
1034
1034
{
@@ -1156,23 +1156,19 @@ describeOneTableDetails(const char *schemaname,
1156
1156
PQclear (result );
1157
1157
}
1158
1158
1159
- /* Get column info (index requires additional checks) */
1159
+ /* Get column info */
1160
1160
printfPQExpBuffer (& buf , "SELECT a.attname," );
1161
1161
appendPQExpBuffer (& buf , "\n pg_catalog.format_type(a.atttypid, a.atttypmod),"
1162
1162
"\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
1163
1163
"\n FROM pg_catalog.pg_attrdef d"
1164
1164
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
1165
1165
"\n a.attnotnull, a.attnum" );
1166
1166
if (tableinfo .relkind == 'i' )
1167
- appendPQExpBuffer (& buf , ", pg_get_indexdef(i.indexrelid, a.attnum, TRUE) AS indexdef" );
1167
+ appendPQExpBuffer (& buf , ",\n pg_catalog. pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef" );
1168
1168
if (verbose )
1169
- appendPQExpBuffer (& buf , ", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)" );
1169
+ appendPQExpBuffer (& buf , ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)" );
1170
1170
appendPQExpBuffer (& buf , "\nFROM pg_catalog.pg_attribute a" );
1171
- if (tableinfo .relkind == 'i' )
1172
- appendPQExpBuffer (& buf , ", pg_catalog.pg_index i" );
1173
1171
appendPQExpBuffer (& buf , "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped" , oid );
1174
- if (tableinfo .relkind == 'i' )
1175
- appendPQExpBuffer (& buf , " AND a.attrelid = i.indexrelid" );
1176
1172
appendPQExpBuffer (& buf , "\nORDER BY a.attnum" );
1177
1173
1178
1174
res = PSQLexec (buf .data , false);
@@ -1220,9 +1216,9 @@ describeOneTableDetails(const char *schemaname,
1220
1216
}
1221
1217
1222
1218
/* Set the number of columns, and their names */
1223
- cols += 2 ;
1224
1219
headers [0 ] = gettext_noop ("Column" );
1225
1220
headers [1 ] = gettext_noop ("Type" );
1221
+ cols = 2 ;
1226
1222
1227
1223
if (tableinfo .relkind == 'r' || tableinfo .relkind == 'v' )
1228
1224
{
@@ -1302,15 +1298,15 @@ describeOneTableDetails(const char *schemaname,
1302
1298
if (tableinfo .relkind == 'S' )
1303
1299
printTableAddCell (& cont , seq_values [i ], false);
1304
1300
1305
- /* Expression for index */
1301
+ /* Expression for index column */
1306
1302
if (tableinfo .relkind == 'i' )
1307
1303
printTableAddCell (& cont , PQgetvalue (res , i , 5 ), false);
1308
1304
1309
1305
/* Storage and Description */
1310
1306
if (verbose )
1311
1307
{
1312
- int fnum = (tableinfo .relkind == 'i' ? 6 : 5 );
1313
- char * storage = PQgetvalue (res , i , fnum );
1308
+ int firstvcol = (tableinfo .relkind == 'i' ? 6 : 5 );
1309
+ char * storage = PQgetvalue (res , i , firstvcol );
1314
1310
1315
1311
/* these strings are literal in our syntax, so not translated. */
1316
1312
printTableAddCell (& cont , (storage [0 ] == 'p' ? "plain" :
@@ -1319,7 +1315,7 @@ describeOneTableDetails(const char *schemaname,
1319
1315
(storage [0 ] == 'e' ? "external" :
1320
1316
"???" )))),
1321
1317
false);
1322
- printTableAddCell (& cont , PQgetvalue (res , i , fnum + 1 ), false);
1318
+ printTableAddCell (& cont , PQgetvalue (res , i , firstvcol + 1 ), false);
1323
1319
}
1324
1320
}
1325
1321
@@ -1844,20 +1840,23 @@ describeOneTableDetails(const char *schemaname,
1844
1840
}
1845
1841
else
1846
1842
{
1847
- /* display the list of child tables*/
1843
+ /* display the list of child tables */
1844
+ const char * ct = _ ("Child tables" );
1845
+
1848
1846
for (i = 0 ; i < tuples ; i ++ )
1849
- {
1850
- const char * ct = _ ("Child tables" );
1851
-
1852
- if (i == 0 )
1853
- printfPQExpBuffer (& buf , "%s: %s" , ct , PQgetvalue (result , i , 0 ));
1854
- else
1855
- printfPQExpBuffer (& buf , "%*s %s" , (int ) strlen (ct ), "" , PQgetvalue (result , i , 0 ));
1856
- if (i < tuples - 1 )
1857
- appendPQExpBuffer (& buf , "," );
1858
-
1859
- printTableAddFooter (& cont , buf .data );
1860
- }
1847
+ {
1848
+ if (i == 0 )
1849
+ printfPQExpBuffer (& buf , "%s: %s" ,
1850
+ ct , PQgetvalue (result , i , 0 ));
1851
+ else
1852
+ printfPQExpBuffer (& buf , "%*s %s" ,
1853
+ (int ) strlen (ct ), "" ,
1854
+ PQgetvalue (result , i , 0 ));
1855
+ if (i < tuples - 1 )
1856
+ appendPQExpBuffer (& buf , "," );
1857
+
1858
+ printTableAddFooter (& cont , buf .data );
1859
+ }
1861
1860
}
1862
1861
PQclear (result );
1863
1862
0 commit comments