Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 57748fc

Browse files
committed
> Having read the list, and noticed the message about table inheritance I
> thought that I would see if I could come up with a simple solution, and > have my first delve into the code for PostgreSQL. > > Attached is a diff against 7.3.3 source, of changes to describe.c for > psql. This should print out a list of parent tables in a similar style > to that of the index listing. I have done some testing on my side and it > all seems fine, can some other people have a quick look? What do people > think? Useful? Nick Barr
1 parent b92d055 commit 57748fc

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/bin/psql/describe.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.79 2003/07/23 08:47:39 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.80 2003/07/25 21:42:26 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -928,12 +928,14 @@ describeOneTableDetails(const char *schemaname,
928928
*result2 = NULL,
929929
*result3 = NULL,
930930
*result4 = NULL,
931-
*result5 = NULL;
931+
*result5 = NULL,
932+
*result6 = NULL;
932933
int check_count = 0,
933934
index_count = 0,
934935
foreignkey_count = 0,
935936
rule_count = 0,
936-
trigger_count = 0;
937+
trigger_count = 0,
938+
inherits_count = 0;
937939
int count_footers = 0;
938940

939941
/* count indexes */
@@ -1037,7 +1039,16 @@ describeOneTableDetails(const char *schemaname,
10371039
foreignkey_count = PQntuples(result5);
10381040
}
10391041

1040-
footers = xmalloczero((index_count + check_count + rule_count + trigger_count + foreignkey_count + 6)
1042+
/* count inherited tables */
1043+
printfPQExpBuffer(&buf, "SELECT c.relname FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno ASC", oid);
1044+
1045+
result6 = PSQLexec(buf.data, false);
1046+
if (!result6)
1047+
goto error_return;
1048+
else
1049+
inherits_count = PQntuples(result6);
1050+
1051+
footers = xmalloczero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 6)
10411052
* sizeof(*footers));
10421053

10431054
/* print indexes */
@@ -1140,6 +1151,21 @@ describeOneTableDetails(const char *schemaname,
11401151
}
11411152
}
11421153

1154+
/* print inherits */
1155+
for (i = 0; i < inherits_count; i++)
1156+
{
1157+
char *s = _("Inherits");
1158+
1159+
if (i == 0)
1160+
printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result6, i, 0));
1161+
else
1162+
printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result6, i, 0));
1163+
if (i < inherits_count - 1)
1164+
appendPQExpBuffer(&buf, ",");
1165+
1166+
footers[count_footers++] = xstrdup(buf.data);
1167+
}
1168+
11431169
/* end of list marker */
11441170
footers[count_footers] = NULL;
11451171

@@ -1148,6 +1174,7 @@ describeOneTableDetails(const char *schemaname,
11481174
PQclear(result3);
11491175
PQclear(result4);
11501176
PQclear(result5);
1177+
PQclear(result6);
11511178
}
11521179

11531180
printTable(title.data, headers,

0 commit comments

Comments
 (0)