Index: svn://svn.pgadmin.org/trunk/pgadmin3/pgadmin/schema/pgObject.cpp
===================================================================
--- svn://svn.pgadmin.org/trunk/pgadmin3/pgadmin/schema/pgObject.cpp	(revision 7577)
+++ svn://svn.pgadmin.org/trunk/pgadmin3/pgadmin/schema/pgObject.cpp	(working copy)
@@ -335,7 +335,7 @@
     else
         where = wh;
     ShowDependency(GetDatabase(), Dependencies,
-        wxT("SELECT DISTINCT deptype, refclassid, cl.relkind,\n")
+        wxT("SELECT DISTINCT dep.deptype, dep.refclassid, cl.relkind,\n")
         wxT("       CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.refobjsubid::text, '')\n")
         wxT("            WHEN tg.oid IS NOT NULL THEN 'T'::text\n")
         wxT("            WHEN ty.oid IS NOT NULL THEN 'y'::text\n")
@@ -346,23 +346,23 @@
         wxT("            WHEN co.oid IS NOT NULL THEN 'C'::text || contype\n")
         wxT("            ELSE '' END AS type,\n")
         wxT("       COALESCE(coc.relname, clrw.relname) AS ownertable,\n")
-        wxT("       COALESCE(cl.relname || '.' || att.attname, cl.relname, conname, proname, tgname, typname, lanname, rulename, ns.nspname) AS refname,\n")
+        wxT("       COALESCE(cl.relname || '.' || att.attname, cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname) AS refname,\n")
         wxT("       COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname\n")
         wxT("  FROM pg_depend dep\n")
         wxT("  LEFT JOIN pg_class cl ON dep.refobjid=cl.oid\n")
-		wxT("  LEFT JOIN pg_attribute att ON dep.refobjid=att.attrelid AND dep.refobjsubid=att.attnum")
+		wxT("  LEFT JOIN pg_attribute att ON dep.refobjid=att.attrelid AND dep.refobjsubid=att.attnum\n")
         wxT("  LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid\n")
-        wxT("  LEFT JOIN pg_proc pr on dep.refobjid=pr.oid\n")
-        wxT("  LEFT JOIN pg_namespace nsp ON pronamespace=nsp.oid\n")
+        wxT("  LEFT JOIN pg_proc pr ON dep.refobjid=pr.oid\n")
+        wxT("  LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid\n")
         wxT("  LEFT JOIN pg_trigger tg ON dep.refobjid=tg.oid\n")
-        wxT("  LEFT JOIN pg_type ty on dep.refobjid=ty.oid\n")
-        wxT("  LEFT JOIN pg_namespace nst ON typnamespace=nst.oid\n")
+        wxT("  LEFT JOIN pg_type ty ON dep.refobjid=ty.oid\n")
+        wxT("  LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid\n")
         wxT("  LEFT JOIN pg_constraint co ON dep.refobjid=co.oid\n")
-        wxT("  LEFT JOIN pg_class coc ON conrelid=coc.oid\n")
-        wxT("  LEFT JOIN pg_namespace nso ON connamespace=nso.oid\n")
+        wxT("  LEFT JOIN pg_class coc ON co.conrelid=coc.oid\n")
+        wxT("  LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid\n")
         wxT("  LEFT JOIN pg_rewrite rw ON dep.refobjid=rw.oid\n")
         wxT("  LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class\n")
-        wxT("  LEFT JOIN pg_namespace nsrw ON cl.relnamespace=nsrw.oid\n")
+        wxT("  LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid\n")
         wxT("  LEFT JOIN pg_language la ON dep.refobjid=la.oid\n")
         wxT("  LEFT JOIN pg_namespace ns ON dep.refobjid=ns.oid\n")
         + where, wxT("refclassid"));
@@ -406,7 +406,7 @@
     else
         where = wh;
     ShowDependency(GetDatabase(), referencedBy,
-        wxT("SELECT DISTINCT deptype, classid, cl.relkind,\n")
+        wxT("SELECT DISTINCT dep.deptype, dep.classid, cl.relkind,\n")
         wxT("       CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.objsubid::text, '')\n")
         wxT("            WHEN tg.oid IS NOT NULL THEN 'T'::text\n")
         wxT("            WHEN ty.oid IS NOT NULL THEN 'y'::text\n")
@@ -417,23 +417,23 @@
         wxT("            WHEN co.oid IS NOT NULL THEN 'C'::text || contype\n")
         wxT("            ELSE '' END AS type,\n")
         wxT("       COALESCE(coc.relname, clrw.relname) AS ownertable,\n")
-        wxT("       COALESCE(cl.relname || '.' || att.attname, cl.relname, conname, proname, tgname, typname, lanname, rulename, ns.nspname) AS refname,\n")
+		wxT("       COALESCE(cl.relname || '.' || att.attname, cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname) AS refname,\n")
         wxT("       COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname\n")
         wxT("  FROM pg_depend dep\n")
         wxT("  LEFT JOIN pg_class cl ON dep.objid=cl.oid\n")
-		wxT("  LEFT JOIN pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum")
+		wxT("  LEFT JOIN pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum\n")
         wxT("  LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid\n")
-        wxT("  LEFT JOIN pg_proc pr on dep.objid=pr.oid\n")
-        wxT("  LEFT JOIN pg_namespace nsp ON pronamespace=nsp.oid\n")
+        wxT("  LEFT JOIN pg_proc pr ON dep.objid=pr.oid\n")
+        wxT("  LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid\n")
         wxT("  LEFT JOIN pg_trigger tg ON dep.objid=tg.oid\n")
-        wxT("  LEFT JOIN pg_type ty on dep.objid=ty.oid\n")
-        wxT("  LEFT JOIN pg_namespace nst ON typnamespace=nst.oid\n")
-        wxT("  LEFT JOIN pg_constraint co on dep.objid=co.oid\n")
-        wxT("  LEFT JOIN pg_class coc ON conrelid=coc.oid\n")
-        wxT("  LEFT JOIN pg_namespace nso ON connamespace=nso.oid\n")
+        wxT("  LEFT JOIN pg_type ty ON dep.objid=ty.oid\n")
+        wxT("  LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid\n")
+        wxT("  LEFT JOIN pg_constraint co ON dep.objid=co.oid\n")
+        wxT("  LEFT JOIN pg_class coc ON co.conrelid=coc.oid\n")
+        wxT("  LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid\n")
         wxT("  LEFT JOIN pg_rewrite rw ON dep.objid=rw.oid\n")
         wxT("  LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class\n")
-        wxT("  LEFT JOIN pg_namespace nsrw ON cl.relnamespace=nsrw.oid\n")
+        wxT("  LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid\n")
         wxT("  LEFT JOIN pg_language la ON dep.objid=la.oid\n")
         wxT("  LEFT JOIN pg_namespace ns ON dep.objid=ns.oid\n")
         + where, wxT("classid"));
