*** pgsql/src/bin/psql/describe.c 2009/07/06 17:01:42 1.220 --- pgsql/src/bin/psql/describe.c 2009/07/07 16:28:38 1.221 *************** *** 8,14 **** * * Copyright (c) 2000-2009, PostgreSQL Global Development Group * ! * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.219 2009/07/03 18:56:50 petere Exp $ */ #include "postgres_fe.h" --- 8,14 ---- * * Copyright (c) 2000-2009, PostgreSQL Global Development Group * ! * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.220 2009/07/06 17:01:42 petere Exp $ */ #include "postgres_fe.h" *************** describeOneTableDetails(const char *sche *** 1028,1034 **** char **ptr; PQExpBufferData title; PQExpBufferData tmpbuf; ! int cols = 0; int numrows = 0; struct { --- 1028,1034 ---- char **ptr; PQExpBufferData title; PQExpBufferData tmpbuf; ! int cols; int numrows = 0; struct { *************** describeOneTableDetails(const char *sche *** 1156,1162 **** PQclear(result); } ! /* Get column info (index requires additional checks) */ printfPQExpBuffer(&buf, "SELECT a.attname,"); appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod)," "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)" --- 1156,1162 ---- PQclear(result); } ! /* Get column info */ printfPQExpBuffer(&buf, "SELECT a.attname,"); appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod)," "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)" *************** describeOneTableDetails(const char *sche *** 1164,1178 **** "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," "\n a.attnotnull, a.attnum"); if (tableinfo.relkind == 'i') ! appendPQExpBuffer(&buf, ", pg_get_indexdef(i.indexrelid,a.attnum, TRUE) AS indexdef"); if (verbose) ! appendPQExpBuffer(&buf, ", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)"); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); - if (tableinfo.relkind == 'i') - appendPQExpBuffer(&buf, ", pg_catalog.pg_index i"); appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); - if (tableinfo.relkind == 'i') - appendPQExpBuffer(&buf, " AND a.attrelid = i.indexrelid"); appendPQExpBuffer(&buf, "\nORDER BY a.attnum"); res = PSQLexec(buf.data, false); --- 1164,1174 ---- "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," "\n a.attnotnull, a.attnum"); if (tableinfo.relkind == 'i') ! appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef"); if (verbose) ! appendPQExpBuffer(&buf, ",\n a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)"); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); appendPQExpBuffer(&buf, "\nORDER BY a.attnum"); res = PSQLexec(buf.data, false); *************** describeOneTableDetails(const char *sche *** 1220,1228 **** } /* Set the number of columns, and their names */ - cols += 2; headers[0] = gettext_noop("Column"); headers[1] = gettext_noop("Type"); if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v') { --- 1216,1224 ---- } /* Set the number of columns, and their names */ headers[0] = gettext_noop("Column"); headers[1] = gettext_noop("Type"); + cols = 2; if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v') { *************** describeOneTableDetails(const char *sche *** 1302,1316 **** if (tableinfo.relkind == 'S') printTableAddCell(&cont, seq_values[i], false); ! /* Expression for index */ if (tableinfo.relkind == 'i') printTableAddCell(&cont, PQgetvalue(res, i, 5), false); /* Storage and Description */ if (verbose) { ! int fnum = (tableinfo.relkind == 'i' ? 6 : 5); ! char *storage = PQgetvalue(res, i, fnum); /* these strings are literal in our syntax, so not translated. */ printTableAddCell(&cont, (storage[0] == 'p' ? "plain" : --- 1298,1312 ---- if (tableinfo.relkind == 'S') printTableAddCell(&cont, seq_values[i], false); ! /* Expression for index column */ if (tableinfo.relkind == 'i') printTableAddCell(&cont, PQgetvalue(res, i, 5), false); /* Storage and Description */ if (verbose) { ! int firstvcol = (tableinfo.relkind == 'i' ? 6 : 5); ! char *storage = PQgetvalue(res, i, firstvcol); /* these strings are literal in our syntax, so not translated. */ printTableAddCell(&cont, (storage[0] == 'p' ? "plain" : *************** describeOneTableDetails(const char *sche *** 1319,1325 **** (storage[0] == 'e' ? "external" : "???")))), false); ! printTableAddCell(&cont, PQgetvalue(res, i, fnum + 1), false); } } --- 1315,1321 ---- (storage[0] == 'e' ? "external" : "???")))), false); ! printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1), false); } } *************** describeOneTableDetails(const char *sche *** 1844,1863 **** } else { ! /* display the list of child tables*/ ! for (i = 0; i < tuples; i++) ! { ! const char *ct = _("Child tables"); ! if (i == 0) ! printfPQExpBuffer(&buf, "%s: %s", ct, PQgetvalue(result, i, 0)); ! else ! printfPQExpBuffer(&buf, "%*s %s", (int) strlen(ct), "", PQgetvalue(result, i, 0)); ! if (i < tuples - 1) ! appendPQExpBuffer(&buf, ","); ! printTableAddFooter(&cont, buf.data); ! } } PQclear(result); --- 1840,1862 ---- } else { ! /* display the list of child tables */ ! const char *ct = _("Child tables"); ! for (i = 0; i < tuples; i++) ! { ! if (i == 0) ! printfPQExpBuffer(&buf, "%s: %s", ! ct, PQgetvalue(result, i, 0)); ! else ! printfPQExpBuffer(&buf, "%*s %s", ! (int) strlen(ct), "", ! PQgetvalue(result, i, 0)); ! if (i < tuples - 1) ! appendPQExpBuffer(&buf, ","); ! printTableAddFooter(&cont, buf.data); ! } } PQclear(result);