Reference by in \d <table_name> out
Hi,
Refering to this request http://momjian.us/mhonarc/patches_hold/msg00022.html
I have created a patch. The output doesn't exaclty match with what is stated here
http://momjian.us/mhonarc/patches_hold/msg00023.html.
However, it does tell the required details in a similar format. I had posted this on -patches but somehow it is not appearing as a thread and hence I have posted this on hackers.
Comments?
osdb_pgarch=# \d htest
Table "public.htest"
Column | Type | Modifiers
--------------+---------------+-----------
new_id | integer | not null
test_name | character(20) |
test_cust_id | integer |
Indexes:
"htest_pkey" PRIMARY KEY, btree (new_id)
Foreign-key constraints:
"htest_test_cust_id_fkey" FOREIGN KEY (test_cust_id) REFERENCES customers(customer_id)
Refrenced by :
"htest_child_ctest_cust_id_fkey" IN public.htest_child(ctest_cust_id) REFERENCES htest(new_id)
"htest_child1_ctest_cust_id_fkey" IN public.htest_child1(ctest_cust_id) REFERENCES htest(new_id)
diff describe.c_orig describe.c
1109c1109,1110
< *result6 = NULL;
---
*result6 = NULL,
*result7 = NULL;
1114a1116
refof_count = 0,
1247,1248c1249,1265
< footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherit
s_count + 7 + 1)
< * sizeof(*footers));
---
/* 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
refof_count = PQntuples(result7);footers = pg_malloc_zero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inher
its_count + refof_count + 7 + 1) * sizeof(*footers));
1483a1501,1526
/* print reference count details */
if (refof_count > 0)
{
printfPQExpBuffer(&buf, _("Refrenced by :"));
footers[count_footers++] = pg_strdup(buf.data);
for (i = 0; i < refof_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);
}
}
_________________________________________________________________
Tried the new MSN Messenger? It’s cool! Download now.
http://messenger.msn.com/Download/Default.aspx?mkt=en-in
kenneth d'souza wrote:
Refering to this request http://momjian.us/mhonarc/patches_hold/msg00022.html
I have created a patch. The output doesn't exaclty match with what is stated here
http://momjian.us/mhonarc/patches_hold/msg00023.html. However, it
does tell the required details in a similar format.
I think this is a nice idea. Please submit the patch to the
pgsql-patches list, in diff -c format. Thanks.
I had posted this on -patches but somehow it is not appearing as a
thread and hence I have posted this on hackers.
Hmm, I did see it in -patches yesterday I think ...
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support