Index: describe.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.164 diff -c -r1.164 describe.c *** describe.c 1 Jan 2008 19:45:56 -0000 1.164 --- describe.c 3 Mar 2008 04:10:55 -0000 *************** *** 1106,1117 **** *result3 = NULL, *result4 = NULL, *result5 = NULL, ! *result6 = NULL; int check_count = 0, index_count = 0, foreignkey_count = 0, rule_count = 0, trigger_count = 0, inherits_count = 0; int count_footers = 0; --- 1106,1119 ---- *result3 = NULL, *result4 = NULL, *result5 = NULL, ! *result6 = NULL, ! *result7 = NULL; int check_count = 0, index_count = 0, foreignkey_count = 0, rule_count = 0, trigger_count = 0, + referenceby_count = 0, inherits_count = 0; int count_footers = 0; *************** *** 1244,1251 **** else inherits_count = PQntuples(result6); ! footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 7 + 1) ! * sizeof(*footers)); /* print indexes */ if (index_count > 0) --- 1246,1268 ---- else inherits_count = PQntuples(result6); ! /* reference_by count */ ! ! printfPQExpBuffer(&buf,"SELECT c.conname,n.nspname,p2.relname,pg_catalog.pg_get_constraintdef(c.oid, true)\n" ! "FROM pg_catalog.pg_class p, pg_catalog.pg_constraint c, pg_catalog.pg_class p2 \n" ! ",pg_catalog.pg_namespace n WHERE p.oid = '%s' AND c.confrelid = '%s'\n" ! "AND c.conrelid = p2.oid AND n.oid =p2.relnamespace", oid,oid); ! ! result7 = PSQLexec(buf.data, false); ! if (!result7) ! goto error_return; ! else ! referenceby_count = PQntuples(result7); ! ! ! footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + referenceby_count + 7 + 1) * sizeof(*footers)); ! ! /* print indexes */ if (index_count > 0) *************** *** 1481,1486 **** --- 1498,1529 ---- } } + /* print reference count details */ + if (referenceby_count > 0) + { + printfPQExpBuffer(&buf, _("Refrenced by :")); + footers[count_footers++] = pg_strdup(buf.data); + for (i = 0; i < referenceby_count; i++) + { + const char *refbydef; + const char *usingpos; + printfPQExpBuffer(&buf, _(" \"%s\" IN %s.%s"), + PQgetvalue(result7,i,0), + PQgetvalue(result7,i,1), + PQgetvalue(result7,i,2)); + + /* Everything after "FOREIGN KEY " is echoed verbatim */ + refbydef = PQgetvalue(result7, i, 3); + usingpos = strstr(refbydef, "FOREIGN KEY "); + if (usingpos) + refbydef = usingpos + 12; + appendPQExpBuffer(&buf, "%s",refbydef); + + footers[count_footers++] = pg_strdup(buf.data); + } + } + + /* print inherits */ for (i = 0; i < inherits_count; i++) {