diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
new file mode 100644
index d1e7081..ae2b9db
*** a/doc/src/sgml/catalogs.sgml
--- b/doc/src/sgml/catalogs.sgml
***************
*** 2179,2184 ****
--- 2179,2282 ----
    </para>
   </sect1>
  
+  <sect1 id="catalog-pg-comments">
+   <title><structname>pg_comments</structname></title>
+ 
+   <indexterm zone="catalog-pg-comments">
+    <primary>pg_comments</primary>
+   </indexterm>
+ 
+   <para>
+    The <structname>pg_comments</structname> view displays the comments
+    associated with all database objects. Object comments are manipulated
+    using the <command>COMMENT ON</command> command.
+   </para>
+ 
+   <table>
+    <title><structname>pg_comments</> Columns</title>
+ 
+    <tgroup cols="4">
+     <thead>
+      <row>
+       <entry>Name</entry>
+       <entry>Type</entry>
+       <entry>References</entry>
+       <entry>Description</entry>
+      </row>
+     </thead>
+ 
+     <tbody>
+      <row>
+       <entry><structfield>objoid</structfield></entry>
+       <entry><type>oid</type></entry>
+       <entry><literal><link linkend="catalog-pg-description"><structname>pg_description</structname></link>.objoid</literal></entry>
+       <entry>The OID of the object to which the comment pertains.</entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>classoid</structfield></entry>
+       <entry><type>oid</type></entry>
+       <entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
+       <entry>
+        The OID of the system catalog this object appears in
+       </entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>objsubid</structfield></entry>
+       <entry><type>int4</type></entry>
+       <entry><literal><link linkend="catalog-pg-description"><structname>pg_class</structname></link>.objsubid</literal></entry>
+       <entry>
+        For a comment on a table column, this is the column number
+        (the objoid and classoid refer to the table itself). For all other
+        object types, this column is zero.
+       </entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>objtype</structfield></entry>
+       <entry><type>text</type></entry>
+       <entry></entry>
+       <entry>
+        The type of object to which the comment pertains.
+       </entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>objnamespace</structfield></entry>
+       <entry><type>oid</type></entry>
+       <entry><literal><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.oid</literal></entry>
+       <entry>
+        The OID of the namespace that contains this object, if applicable,
+        otherwise 0
+       </entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>objname</structfield></entry>
+       <entry><type>text</type></entry>
+       <entry></entry>
+       <entry>
+        The name of the object
+       </entry>
+      </row>
+ 
+      <row>
+       <entry><structfield>description</structfield></entry>
+       <entry><type>text</type></entry>
+       <entry><literal><link linkend="catalog-pg-description"><structname>pg_description</structname></link>.description</literal> or <literal><link linkend="catalog-pg-shdescription"><structname>pg_shdescription</structname></link>.description</literal></entry>
+       <entry>
+        The comment attached to the object
+       </entry>
+      </row>
+ 
+     </tbody>
+    </tgroup>
+   </table>
+ 
+  </sect1>
+ 
+ 
   <sect1 id="catalog-pg-conversion">
    <title><structname>pg_conversion</structname></title>
  
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
new file mode 100644
index 628fbef..4afafe7
*** a/doc/src/sgml/func.sgml
--- b/doc/src/sgml/func.sgml
*************** SELECT relname FROM pg_class WHERE pg_ta
*** 13102,13107 ****
--- 13102,13113 ----
         <entry>is operator visible in search path</entry>
        </row>
        <row>
+        <entry><literal><function>pg_opfamily_is_visible(<parameter>opclass_oid</parameter>)</function></literal>
+        </entry>
+        <entry><type>boolean</type></entry>
+        <entry>is operator family visible in search path</entry>
+       </row>
+       <row>
         <entry><literal><function>pg_table_is_visible(<parameter>table_oid</parameter>)</function></literal>
         </entry>
         <entry><type>boolean</type></entry>
*************** SELECT relname FROM pg_class WHERE pg_ta
*** 13157,13162 ****
--- 13163,13171 ----
      <primary>pg_operator_is_visible</primary>
     </indexterm>
     <indexterm>
+     <primary>pg_opfamily_is_visible</primary>
+    </indexterm>
+    <indexterm>
      <primary>pg_table_is_visible</primary>
     </indexterm>
     <indexterm>
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
new file mode 100644
index 41e9299..5d54a8e
*** a/src/backend/catalog/namespace.c
--- b/src/backend/catalog/namespace.c
*************** Datum		pg_type_is_visible(PG_FUNCTION_AR
*** 200,205 ****
--- 200,206 ----
  Datum		pg_function_is_visible(PG_FUNCTION_ARGS);
  Datum		pg_operator_is_visible(PG_FUNCTION_ARGS);
  Datum		pg_opclass_is_visible(PG_FUNCTION_ARGS);
+ Datum		pg_opfamily_is_visible(PG_FUNCTION_ARGS);
  Datum		pg_collation_is_visible(PG_FUNCTION_ARGS);
  Datum		pg_conversion_is_visible(PG_FUNCTION_ARGS);
  Datum		pg_ts_parser_is_visible(PG_FUNCTION_ARGS);
*************** pg_collation_is_visible(PG_FUNCTION_ARGS
*** 3787,3792 ****
--- 3788,3804 ----
  }
  
  Datum
+ pg_opfamily_is_visible(PG_FUNCTION_ARGS)
+ {
+ 	Oid			oid = PG_GETARG_OID(0);
+ 
+ 	if (!SearchSysCacheExists1(OPFAMILYOID, ObjectIdGetDatum(oid)))
+ 		PG_RETURN_NULL();
+ 
+ 	PG_RETURN_BOOL(OpfamilyIsVisible(oid));
+ }
+ 
+ Datum
  pg_conversion_is_visible(PG_FUNCTION_ARGS)
  {
  	Oid			oid = PG_GETARG_OID(0);
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
new file mode 100644
index 325d452..3786615
*** a/src/backend/catalog/system_views.sql
--- b/src/backend/catalog/system_views.sql
***************
*** 6,11 ****
--- 6,448 ----
   * src/backend/catalog/system_views.sql
   */
  
+ CREATE VIEW pg_comments AS
+     SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	CASE WHEN rel.relkind = 'r' THEN 'table'::text
+ 		 WHEN rel.relkind = 'v' THEN 'view'::text
+ 		 WHEN rel.relkind = 'i' THEN 'index'::text
+ 		 WHEN rel.relkind = 'S' THEN 'sequence'::text
+ 		 WHEN rel.relkind = 'f' THEN 'foreign table'::text END AS objtype,
+ 	rel.relnamespace AS objnamespace,
+ 	CASE WHEN pg_table_is_visible(rel.oid)
+ 		 THEN quote_ident(rel.relname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_class rel ON d.classoid = rel.tableoid AND d.objoid = rel.oid
+ 	JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'column'::text AS objtype,
+ 	rel.relnamespace AS objnamespace,
+ 	CASE WHEN pg_table_is_visible(rel.oid)
+ 		 THEN quote_ident(rel.relname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
+ 		 END || '.' || att.attname AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_class rel ON d.classoid = rel.tableoid AND d.objoid = rel.oid
+ 	JOIN pg_attribute att
+ 		ON rel.oid = att.attrelid AND d.objsubid = att.attnum
+ 	JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+ WHERE
+ 	d.objsubid != 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	CASE WHEN pro.proisagg = true THEN 'aggregate'::text
+ 		 WHEN pro.proisagg = false THEN 'function'::text
+ 		 END AS objtype,
+ 	pro.pronamespace AS objnamespace,
+ 	CASE WHEN pg_function_is_visible(pro.oid)
+ 		 THEN quote_ident(pro.proname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(pro.proname)
+ 		 END || '('
+ 		 || pg_catalog.pg_get_function_arguments(pro.oid) || ')' AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_proc pro ON d.classoid = pro.tableoid AND d.objoid = pro.oid
+ 	JOIN pg_namespace nsp ON pro.pronamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'cast'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	'(' || format_type(cst.castsource, NULL)
+ 		|| ' AS ' || format_type(cst.casttarget, NULL) || ')' AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_cast cst ON d.classoid = cst.tableoid AND d.objoid = cst.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+         'collation'::text AS objtype,
+         col.collnamespace AS objnamespace,
+         col.collname AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_collation col ON d.classoid = col.tableoid AND d.objoid = col.oid
+ 	JOIN pg_namespace nsp ON col.collnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'constraint'::text AS objtype,
+ 	rel.relnamespace AS objnamespace,
+ 	con.conname || ' ON ' ||
+ 	CASE WHEN pg_table_is_visible(rel.oid)
+ 		 THEN quote_ident(rel.relname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_constraint con ON d.classoid = con.tableoid AND d.objoid = con.oid
+ 	JOIN pg_class rel ON con.conrelid = rel.oid
+ 	JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'conversion'::text AS objtype,
+ 	con.connamespace AS objnamespace,
+ 	CASE WHEN pg_conversion_is_visible(con.oid)
+ 		 THEN quote_ident(con.conname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(con.conname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_conversion con ON d.classoid = con.tableoid AND d.objoid = con.oid
+ 	JOIN pg_namespace nsp ON con.connamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	CASE WHEN typ.typtype = 'd' THEN 'domain'::text
+ 		 ELSE 'type'::text END AS objtype,
+ 	typ.typnamespace AS objnamespace,
+ 	CASE WHEN pg_type_is_visible(typ.oid)
+ 		 THEN quote_ident(typ.typname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(typ.typname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_type typ ON d.classoid = typ.tableoid AND d.objoid = typ.oid
+ 	JOIN pg_namespace nsp ON typ.typnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'extension'::text AS objtype,
+ 	ext.extnamespace AS objnamespace,
+ 	ext.extname AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_extension ext ON d.classoid = ext.tableoid AND d.objoid = ext.oid
+ 	JOIN pg_namespace nsp ON ext.extnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'large object'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	d.objoid::text AS objname,
+ 	d.description,
+ 	false AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_largeobject_metadata lom ON d.objoid = lom.oid
+ WHERE
+ 	d.classoid = (SELECT oid FROM pg_class WHERE relname = 'pg_largeobject')
+ 	AND d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'operator'::text AS objtype,
+ 	opr.oprnamespace AS objnamespace,
+ 	CASE WHEN pg_operator_is_visible(opr.oid)
+ 		 THEN opr.oprname
+ 		 ELSE quote_ident(nsp.nspname) || '.' || opr.oprname
+ 		 END
+ 		|| '('
+ 		|| CASE WHEN opr.oprkind = 'r' THEN 'NONE'
+ 				ELSE format_type(opr.oprleft, NULL) END
+ 		|| ','
+ 		|| CASE WHEN opr.oprkind = 'l' THEN 'NONE'
+ 				ELSE format_type(opr.oprright, NULL) END
+ 		|| ')' AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_operator opr ON d.classoid = opr.tableoid AND d.objoid = opr.oid
+ 	JOIN pg_namespace nsp ON opr.oprnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'operator class'::text AS objtype,
+ 	opc.opcnamespace AS objnamespace,
+ 	CASE WHEN pg_opclass_is_visible(opc.oid)
+ 		 THEN quote_ident(opc.opcname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(opc.opcname)
+ 		 END || ' USING ' || am.amname AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_opclass opc ON d.classoid = opc.tableoid AND d.objoid = opc.oid
+ 	JOIN pg_am am ON opc.opcmethod = am.oid
+ 	JOIN pg_namespace nsp ON opc.opcnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'operator family'::text AS objtype,
+ 	opf.opfnamespace AS objnamespace,
+ 	CASE WHEN pg_opfamily_is_visible(opf.oid)
+ 		 THEN quote_ident(opf.opfname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(opf.opfname)
+ 		 END || ' USING ' || am.amname AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_opfamily opf ON d.classoid = opf.tableoid AND d.objoid = opf.oid
+ 	JOIN pg_am am ON opf.opfmethod = am.oid
+ 	JOIN pg_namespace nsp ON opf.opfnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'language'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(lan.lanname) AS objname,
+ 	d.description,
+ 	lan.lanplcallfoid = 0 AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_language lan ON d.classoid = lan.tableoid AND d.objoid = lan.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'rule'::text AS objtype,
+ 	rel.relnamespace AS objnamespace,
+ 	quote_ident(rew.rulename) || ' ON ' ||
+ 	CASE WHEN pg_table_is_visible(rel.oid)
+ 		 THEN quote_ident(rel.relname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_rewrite rew ON d.classoid = rew.tableoid AND d.objoid = rew.oid
+ 	JOIN pg_class rel ON rew.ev_class = rel.oid
+ 	JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'schema'::text AS objtype,
+ 	nsp.oid AS objnamespace,
+ 	quote_ident(nsp.nspname) AS objname,
+ 	d.description,
+ 	nsp.nspname = 'information_schema' OR nsp.nspname ~ '^pg_' AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_namespace nsp ON d.classoid = nsp.tableoid AND d.objoid = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'text search configuration'::text AS objtype,
+ 	cfg.cfgnamespace AS objnamespace,
+ 	CASE WHEN pg_ts_config_is_visible(cfg.oid)
+ 		 THEN quote_ident(cfg.cfgname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(cfg.cfgname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_ts_config cfg ON d.classoid = cfg.tableoid AND d.objoid = cfg.oid
+ 	JOIN pg_namespace nsp ON cfg.cfgnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'text search dictionary'::text AS objtype,
+ 	dict.dictnamespace AS objnamespace,
+ 	CASE WHEN pg_ts_dict_is_visible(dict.oid)
+ 		 THEN quote_ident(dict.dictname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(dict.dictname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_ts_dict dict ON d.classoid = dict.tableoid AND d.objoid = dict.oid
+ 	JOIN pg_namespace nsp ON dict.dictnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'text search parser'::text AS objtype,
+ 	prs.prsnamespace AS objnamespace,
+ 	CASE WHEN pg_ts_parser_is_visible(prs.oid)
+ 		 THEN quote_ident(prs.prsname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(prs.prsname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_ts_parser prs ON d.classoid = prs.tableoid AND d.objoid = prs.oid
+ 	JOIN pg_namespace nsp ON prs.prsnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'text search template'::text AS objtype,
+ 	tmpl.tmplnamespace AS objnamespace,
+ 	CASE WHEN pg_ts_template_is_visible(tmpl.oid)
+ 		 THEN quote_ident(tmpl.tmplname)
+ 		 ELSE quote_ident(nsp.nspname) || '.' || quote_ident(tmpl.tmplname)
+ 		 END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_ts_template tmpl
+ 		ON d.classoid = tmpl.tableoid AND d.objoid = tmpl.oid
+ 	JOIN pg_namespace nsp ON tmpl.tmplnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'trigger'::text AS objtype,
+ 	rel.relnamespace AS objnamespace,
+ 	quote_ident(tg.tgname) || ' ON ' ||
+ 	CASE WHEN pg_table_is_visible(rel.oid)
+ 	     THEN quote_ident(rel.relname)
+ 	     ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
+ 	     END AS objname,
+ 	d.description,
+ 	nsp.nspname IN ('pg_catalog', 'information_schema') AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_trigger tg ON d.classoid = tg.tableoid AND d.objoid = tg.oid
+ 	JOIN pg_class rel ON tg.tgrelid = rel.oid
+ 	JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'access method'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(am.amname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_am am ON d.classoid = am.tableoid AND d.objoid = am.oid
+ WHERE
+ 	d.objsubid = 0
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, NULL::integer AS objsubid,
+ 	'database'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(dat.datname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_shdescription d
+ 	JOIN pg_database dat ON d.classoid = dat.tableoid AND d.objoid = dat.oid
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, NULL::integer AS objsubid,
+ 	'role'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(rol.rolname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_shdescription d
+ 	JOIN pg_authid rol ON d.classoid = rol.tableoid AND d.objoid = rol.oid
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, NULL::integer AS objsubid,
+ 	'tablespace'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(spc.spcname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_shdescription d
+ 	JOIN pg_tablespace spc
+ 		ON d.classoid = spc.tableoid AND d.objoid = spc.oid
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'foreign data wrapper'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(fdw.fdwname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_foreign_data_wrapper fdw
+ 		ON d.classoid = fdw.tableoid AND d.objoid = fdw.oid
+ UNION ALL
+ SELECT
+ 	d.objoid, d.classoid, d.objsubid,
+ 	'server'::text AS objtype,
+ 	NULL::oid AS objnamespace,
+ 	quote_ident(srv.srvname) AS objname,
+ 	d.description,
+ 	true AS is_system
+ FROM
+ 	pg_description d
+ 	JOIN pg_foreign_server srv
+ 		ON d.classoid = srv.tableoid AND d.objoid = srv.oid;
+ 
+ 
+ 
  CREATE VIEW pg_roles AS
      SELECT
          rolname,
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
new file mode 100644
index b2c54b5..612c054
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
*************** listDefaultACLs(const char *pattern)
*** 830,837 ****
   *
   * \dd [foo]
   *
!  * Note: This only lists things that actually have a description. For complete
!  * lists of things, there are other \d? commands.
   */
  bool
  objectDescription(const char *pattern, bool showSystem)
--- 830,841 ----
   *
   * \dd [foo]
   *
!  * Note: This command only lists comments for object types who do not have
!  * their comments displayed within their own backslash commands. The following
!  * types of objects will be displayed: domain, function, foreign table, index,
!  * operator, operator class, operator family, rule, table, trigger, view,
!  * sequence
!  * 
   */
  bool
  objectDescription(const char *pattern, bool showSystem)
*************** objectDescription(const char *pattern, b
*** 843,848 ****
--- 847,880 ----
  
  	initPQExpBuffer(&buf);
  
+ 	/* As of 9.2, we have the pg_comments view containing comments for all
+ 	 * objects.
+ 	 */
+ 	if (pset.sversion >= 90200)
+ 	{
+ 		appendPQExpBuffer(&buf,
+ 						  "SELECT nsp.nspname AS \"%s\", objname AS \"%s\", objtype AS \"%s\", description AS \"%s\"\n"
+ 						  "FROM pg_comments pgc "
+ 						  "LEFT JOIN pg_namespace nsp "
+ 						  "ON pgc.objnamespace = nsp.oid "
+ 						  "WHERE objtype IN ('constraint', 'domain', 'index', 'foreign table', 'function', 'operator', 'operator class', 'operator family', 'rule', 'sequence', 'table', 'trigger', 'view')",
+ 						  gettext_noop("Schema"),
+ 						  gettext_noop("Name"),
+ 						  gettext_noop("Object"),
+ 						  gettext_noop("Description"));
+ 		if (!showSystem && !pattern)
+ 			appendPQExpBuffer(&buf, " AND is_system = false ");
+ 
+ 		processSQLNamePattern(pset.db, &buf, pattern, true, false,
+ 							  "nsp.nspname", "objname", NULL,
+ 							  NULL);
+ 	}
+ 	/* Otherwise, we have to piece together comments from various catalogs
+ 	 * ourselves.
+ 	 */
+ 	else
+ 	{
+ 						  
  	appendPQExpBuffer(&buf,
  					  "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
  					  "FROM (\n",
*************** objectDescription(const char *pattern, b
*** 851,878 ****
  					  gettext_noop("Object"),
  					  gettext_noop("Description"));
  
- 	/* Aggregate descriptions */
- 	appendPQExpBuffer(&buf,
- 					  "  SELECT p.oid as oid, p.tableoid as tableoid,\n"
- 					  "  n.nspname as nspname,\n"
- 					  "  CAST(p.proname AS pg_catalog.text) as name,"
- 					  "  CAST('%s' AS pg_catalog.text) as object\n"
- 					  "  FROM pg_catalog.pg_proc p\n"
- 	 "       LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
- 					  "  WHERE p.proisagg\n",
- 					  gettext_noop("aggregate"));
- 
- 	if (!showSystem && !pattern)
- 		appendPQExpBuffer(&buf, "      AND n.nspname <> 'pg_catalog'\n"
- 						  "      AND n.nspname <> 'information_schema'\n");
- 
- 	processSQLNamePattern(pset.db, &buf, pattern, true, false,
- 						  "n.nspname", "p.proname", NULL,
- 						  "pg_catalog.pg_function_is_visible(p.oid)");
- 
  	/* Function descriptions */
  	appendPQExpBuffer(&buf,
- 					  "UNION ALL\n"
  					  "  SELECT p.oid as oid, p.tableoid as tableoid,\n"
  					  "  n.nspname as nspname,\n"
  					  "  CAST(p.proname AS pg_catalog.text) as name,"
--- 883,890 ----
*************** objectDescription(const char *pattern, b
*** 1002,1007 ****
--- 1014,1021 ----
  					  ") AS tt\n"
  					  "  JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
  
+ 	}
+ 
  	appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
  
  	res = PSQLexec(buf.data, false);
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
new file mode 100644
index 6980d3e..f229c5b
*** a/src/include/catalog/pg_proc.h
--- b/src/include/catalog/pg_proc.h
*************** DATA(insert OID = 2082 (  pg_operator_is
*** 2829,2834 ****
--- 2829,2836 ----
  DESCR("is operator visible in search path?");
  DATA(insert OID = 2083 (  pg_opclass_is_visible		PGNSP PGUID 12 1 0 0 0 f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opclass_is_visible _null_ _null_ _null_ ));
  DESCR("is opclass visible in search path?");
+ DATA(insert OID = 3534 (  pg_opfamily_is_visible 	PGNSP PGUID 12 1 0 0 0 f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_opfamily_is_visible _null_ _null_ _null_ ));
+ DESCR("is opfamily visible in search path?");
  DATA(insert OID = 2093 (  pg_conversion_is_visible	PGNSP PGUID 12 1 0 0 0 f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_conversion_is_visible _null_ _null_ _null_ ));
  DESCR("is conversion visible in search path?");
  DATA(insert OID = 3756 (  pg_ts_parser_is_visible	PGNSP PGUID 12 1 0 0 0 f f f t f s 1 0 16 "26" _null_ _null_ _null_ _null_ pg_ts_parser_is_visible _null_ _null_ _null_ ));
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
new file mode 100644
index 20cdc39..2f9356b
*** a/src/test/regress/expected/rules.out
--- b/src/test/regress/expected/rules.out
*************** drop table cchild;
*** 1276,1286 ****
  -- Check that ruleutils are working
  --
  SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schema' ORDER BY viewname;
!             viewname             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
! ---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   iexit                           | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
   pg_available_extension_versions | SELECT e.name, e.version, (x.extname IS NOT NULL) AS installed, e.superuser, e.relocatable, e.schema, e.requires, e.comment FROM (pg_available_extension_versions() e(name, version, superuser, relocatable, schema, requires, comment) LEFT JOIN pg_extension x ON (((e.name = x.extname) AND (e.version = x.extversion))));
   pg_available_extensions         | SELECT e.name, e.default_version, x.extversion AS installed_version, e.comment FROM (pg_available_extensions() e(name, default_version, comment) LEFT JOIN pg_extension x ON ((e.name = x.extname)));
   pg_cursors                      | SELECT c.name, c.statement, c.is_holdable, c.is_binary, c.is_scrollable, c.creation_time FROM pg_cursor() c(name, statement, is_holdable, is_binary, is_scrollable, creation_time);
   pg_group                        | SELECT pg_authid.rolname AS groname, pg_authid.oid AS grosysid, ARRAY(SELECT pg_auth_members.member FROM pg_auth_members WHERE (pg_auth_members.roleid = pg_authid.oid)) AS grolist FROM pg_authid WHERE (NOT pg_authid.rolcanlogin);
   pg_indexes                      | SELECT n.nspname AS schemaname, c.relname AS tablename, i.relname AS indexname, t.spcname AS tablespace, pg_get_indexdef(i.oid) AS indexdef FROM ((((pg_index x JOIN pg_class c ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) LEFT JOIN pg_tablespace t ON ((t.oid = i.reltablespace))) WHERE ((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char"));
--- 1276,1287 ----
  -- Check that ruleutils are working
  --
  SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schema' ORDER BY viewname;
!             viewname             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       definition                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
! ---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   iexit                           | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
   pg_available_extension_versions | SELECT e.name, e.version, (x.extname IS NOT NULL) AS installed, e.superuser, e.relocatable, e.schema, e.requires, e.comment FROM (pg_available_extension_versions() e(name, version, superuser, relocatable, schema, requires, comment) LEFT JOIN pg_extension x ON (((e.name = x.extname) AND (e.version = x.extversion))));
   pg_available_extensions         | SELECT e.name, e.default_version, x.extversion AS installed_version, e.comment FROM (pg_available_extensions() e(name, default_version, comment) LEFT JOIN pg_extension x ON ((e.name = x.extname)));
+  pg_comments                     | (((((((((((((((((((((((((SELECT d.objoid, d.classoid, d.objsubid, CASE WHEN (rel.relkind = 'r'::"char") THEN 'table'::text WHEN (rel.relkind = 'v'::"char") THEN 'view'::text WHEN (rel.relkind = 'i'::"char") THEN 'index'::text WHEN (rel.relkind = 'S'::"char") THEN 'sequence'::text WHEN (rel.relkind = 'f'::"char") THEN 'foreign table'::text ELSE NULL::text END AS objtype, rel.relnamespace AS objnamespace, CASE WHEN pg_table_is_visible(rel.oid) THEN quote_ident((rel.relname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((rel.relname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_class rel ON (((d.classoid = rel.tableoid) AND (d.objoid = rel.oid)))) JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid))) WHERE (d.objsubid = 0) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'column'::text AS objtype, rel.relnamespace AS objnamespace, ((CASE WHEN pg_table_is_visible(rel.oid) THEN quote_ident((rel.relname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((rel.relname)::text)) END || '.'::text) || (att.attname)::text) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_class rel ON (((d.classoid = rel.tableoid) AND (d.objoid = rel.oid)))) JOIN pg_attribute att ON (((rel.oid = att.attrelid) AND (d.objsubid = att.attnum)))) JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid))) WHERE (d.objsubid <> 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, CASE WHEN (pro.proisagg = true) THEN 'aggregate'::text WHEN (pro.proisagg = false) THEN 'function'::text ELSE NULL::text END AS objtype, pro.pronamespace AS objnamespace, (((CASE WHEN pg_function_is_visible(pro.oid) THEN quote_ident((pro.proname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((pro.proname)::text)) END || '('::text) || pg_get_function_arguments(pro.oid)) || ')'::text) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_proc pro ON (((d.classoid = pro.tableoid) AND (d.objoid = pro.oid)))) JOIN pg_namespace nsp ON ((pro.pronamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'cast'::text AS objtype, NULL::oid AS objnamespace, (((('('::text || format_type(cst.castsource, NULL::integer)) || ' AS '::text) || format_type(cst.casttarget, NULL::integer)) || ')'::text) AS objname, d.description, true AS is_system FROM (pg_description d JOIN pg_cast cst ON (((d.classoid = cst.tableoid) AND (d.objoid = cst.oid)))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'collation'::text AS objtype, col.collnamespace AS objnamespace, col.collname AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_collation col ON (((d.classoid = col.tableoid) AND (d.objoid = col.oid)))) JOIN pg_namespace nsp ON ((col.collnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'constraint'::text AS objtype, rel.relnamespace AS objnamespace, (((con.conname)::text || ' ON '::text) || CASE WHEN pg_table_is_visible(rel.oid) THEN quote_ident((rel.relname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((rel.relname)::text)) END) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_constraint con ON (((d.classoid = con.tableoid) AND (d.objoid = con.oid)))) JOIN pg_class rel ON ((con.conrelid = rel.oid))) JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'conversion'::text AS objtype, con.connamespace AS objnamespace, CASE WHEN pg_conversion_is_visible(con.oid) THEN quote_ident((con.conname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((con.conname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_conversion con ON (((d.classoid = con.tableoid) AND (d.objoid = con.oid)))) JOIN pg_namespace nsp ON ((con.connamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, CASE WHEN (typ.typtype = 'd'::"char") THEN 'domain'::text ELSE 'type'::text END AS objtype, typ.typnamespace AS objnamespace, CASE WHEN pg_type_is_visible(typ.oid) THEN quote_ident((typ.typname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((typ.typname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_type typ ON (((d.classoid = typ.tableoid) AND (d.objoid = typ.oid)))) JOIN pg_namespace nsp ON ((typ.typnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'extension'::text AS objtype, ext.extnamespace AS objnamespace, ext.extname AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_extension ext ON (((d.classoid = ext.tableoid) AND (d.objoid = ext.oid)))) JOIN pg_namespace nsp ON ((ext.extnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'large object'::text AS objtype, NULL::oid AS objnamespace, (d.objoid)::text AS objname, d.description, false AS is_system FROM (pg_description d JOIN pg_largeobject_metadata lom ON ((d.objoid = lom.oid))) WHERE ((d.classoid = (SELECT pg_class.oid FROM pg_class WHERE (pg_class.relname = 'pg_largeobject'::name))) AND (d.objsubid = 0))) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'operator'::text AS objtype, opr.oprnamespace AS objnamespace, (((((CASE WHEN pg_operator_is_visible(opr.oid) THEN (opr.oprname)::text ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || (opr.oprname)::text) END || '('::text) || CASE WHEN (opr.oprkind = 'r'::"char") THEN 'NONE'::text ELSE format_type(opr.oprleft, NULL::integer) END) || ','::text) || CASE WHEN (opr.oprkind = 'l'::"char") THEN 'NONE'::text ELSE format_type(opr.oprright, NULL::integer) END) || ')'::text) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_operator opr ON (((d.classoid = opr.tableoid) AND (d.objoid = opr.oid)))) JOIN pg_namespace nsp ON ((opr.oprnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'operator class'::text AS objtype, opc.opcnamespace AS objnamespace, ((CASE WHEN pg_opclass_is_visible(opc.oid) THEN quote_ident((opc.opcname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((opc.opcname)::text)) END || ' USING '::text) || (am.amname)::text) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_opclass opc ON (((d.classoid = opc.tableoid) AND (d.objoid = opc.oid)))) JOIN pg_am am ON ((opc.opcmethod = am.oid))) JOIN pg_namespace nsp ON ((opc.opcnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'operator family'::text AS objtype, opf.opfnamespace AS objnamespace, ((CASE WHEN pg_opfamily_is_visible(opf.oid) THEN quote_ident((opf.opfname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((opf.opfname)::text)) END || ' USING '::text) || (am.amname)::text) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_opfamily opf ON (((d.classoid = opf.tableoid) AND (d.objoid = opf.oid)))) JOIN pg_am am ON ((opf.opfmethod = am.oid))) JOIN pg_namespace nsp ON ((opf.opfnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'language'::text AS objtype, NULL::oid AS objnamespace, quote_ident((lan.lanname)::text) AS objname, d.description, (lan.lanplcallfoid = (0)::oid) AS is_system FROM (pg_description d JOIN pg_language lan ON (((d.classoid = lan.tableoid) AND (d.objoid = lan.oid)))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'rule'::text AS objtype, rel.relnamespace AS objnamespace, ((quote_ident((rew.rulename)::text) || ' ON '::text) || CASE WHEN pg_table_is_visible(rel.oid) THEN quote_ident((rel.relname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((rel.relname)::text)) END) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_rewrite rew ON (((d.classoid = rew.tableoid) AND (d.objoid = rew.oid)))) JOIN pg_class rel ON ((rew.ev_class = rel.oid))) JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'schema'::text AS objtype, nsp.oid AS objnamespace, quote_ident((nsp.nspname)::text) AS objname, d.description, ((nsp.nspname = 'information_schema'::name) OR (nsp.nspname ~ '^pg_'::text)) AS is_system FROM (pg_description d JOIN pg_namespace nsp ON (((d.classoid = nsp.tableoid) AND (d.objoid = nsp.oid)))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'text search configuration'::text AS objtype, cfg.cfgnamespace AS objnamespace, CASE WHEN pg_ts_config_is_visible(cfg.oid) THEN quote_ident((cfg.cfgname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((cfg.cfgname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_ts_config cfg ON (((d.classoid = cfg.tableoid) AND (d.objoid = cfg.oid)))) JOIN pg_namespace nsp ON ((cfg.cfgnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'text search dictionary'::text AS objtype, dict.dictnamespace AS objnamespace, CASE WHEN pg_ts_dict_is_visible(dict.oid) THEN quote_ident((dict.dictname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((dict.dictname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_ts_dict dict ON (((d.classoid = dict.tableoid) AND (d.objoid = dict.oid)))) JOIN pg_namespace nsp ON ((dict.dictnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'text search parser'::text AS objtype, prs.prsnamespace AS objnamespace, CASE WHEN pg_ts_parser_is_visible(prs.oid) THEN quote_ident((prs.prsname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((prs.prsname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_ts_parser prs ON (((d.classoid = prs.tableoid) AND (d.objoid = prs.oid)))) JOIN pg_namespace nsp ON ((prs.prsnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'text search template'::text AS objtype, tmpl.tmplnamespace AS objnamespace, CASE WHEN pg_ts_template_is_visible(tmpl.oid) THEN quote_ident((tmpl.tmplname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((tmpl.tmplname)::text)) END AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM ((pg_description d JOIN pg_ts_template tmpl ON (((d.classoid = tmpl.tableoid) AND (d.objoid = tmpl.oid)))) JOIN pg_namespace nsp ON ((tmpl.tmplnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'trigger'::text AS objtype, rel.relnamespace AS objnamespace, ((quote_ident((tg.tgname)::text) || ' ON '::text) || CASE WHEN pg_table_is_visible(rel.oid) THEN quote_ident((rel.relname)::text) ELSE ((quote_ident((nsp.nspname)::text) || '.'::text) || quote_ident((rel.relname)::text)) END) AS objname, d.description, (nsp.nspname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) AS is_system FROM (((pg_description d JOIN pg_trigger tg ON (((d.classoid = tg.tableoid) AND (d.objoid = tg.oid)))) JOIN pg_class rel ON ((tg.tgrelid = rel.oid))) JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'access method'::text AS objtype, NULL::oid AS objnamespace, quote_ident((am.amname)::text) AS objname, d.description, true AS is_system FROM (pg_description d JOIN pg_am am ON (((d.classoid = am.tableoid) AND (d.objoid = am.oid)))) WHERE (d.objsubid = 0)) UNION ALL SELECT d.objoid, d.classoid, NULL::integer AS objsubid, 'database'::text AS objtype, NULL::oid AS objnamespace, quote_ident((dat.datname)::text) AS objname, d.description, true AS is_system FROM (pg_shdescription d JOIN pg_database dat ON (((d.classoid = dat.tableoid) AND (d.objoid = dat.oid))))) UNION ALL SELECT d.objoid, d.classoid, NULL::integer AS objsubid, 'role'::text AS objtype, NULL::oid AS objnamespace, quote_ident((rol.rolname)::text) AS objname, d.description, true AS is_system FROM (pg_shdescription d JOIN pg_authid rol ON (((d.classoid = rol.tableoid) AND (d.objoid = rol.oid))))) UNION ALL SELECT d.objoid, d.classoid, NULL::integer AS objsubid, 'tablespace'::text AS objtype, NULL::oid AS objnamespace, quote_ident((spc.spcname)::text) AS objname, d.description, true AS is_system FROM (pg_shdescription d JOIN pg_tablespace spc ON (((d.classoid = spc.tableoid) AND (d.objoid = spc.oid))))) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'foreign data wrapper'::text AS objtype, NULL::oid AS objnamespace, quote_ident((fdw.fdwname)::text) AS objname, d.description, true AS is_system FROM (pg_description d JOIN pg_foreign_data_wrapper fdw ON (((d.classoid = fdw.tableoid) AND (d.objoid = fdw.oid))))) UNION ALL SELECT d.objoid, d.classoid, d.objsubid, 'server'::text AS objtype, NULL::oid AS objnamespace, quote_ident((srv.srvname)::text) AS objname, d.description, true AS is_system FROM (pg_description d JOIN pg_foreign_server srv ON (((d.classoid = srv.tableoid) AND (d.objoid = srv.oid))));
   pg_cursors                      | SELECT c.name, c.statement, c.is_holdable, c.is_binary, c.is_scrollable, c.creation_time FROM pg_cursor() c(name, statement, is_holdable, is_binary, is_scrollable, creation_time);
   pg_group                        | SELECT pg_authid.rolname AS groname, pg_authid.oid AS grosysid, ARRAY(SELECT pg_auth_members.member FROM pg_auth_members WHERE (pg_auth_members.roleid = pg_authid.oid)) AS grolist FROM pg_authid WHERE (NOT pg_authid.rolcanlogin);
   pg_indexes                      | SELECT n.nspname AS schemaname, c.relname AS tablename, i.relname AS indexname, t.spcname AS tablespace, pg_get_indexdef(i.oid) AS indexdef FROM ((((pg_index x JOIN pg_class c ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) LEFT JOIN pg_tablespace t ON ((t.oid = i.reltablespace))) WHERE ((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char"));
*************** SELECT viewname, definition FROM pg_view
*** 1338,1344 ****
   shoelace_obsolete               | SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color))));
   street                          | SELECT r.name, r.thepath, c.cname FROM ONLY road r, real_city c WHERE (c.outline ## r.thepath);
   toyemp                          | SELECT emp.name, emp.age, emp.location, (12 * emp.salary) AS annualsal FROM emp;
! (60 rows)
  
  SELECT tablename, rulename, definition FROM pg_rules
  	ORDER BY tablename, rulename;
--- 1339,1345 ----
   shoelace_obsolete               | SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color))));
   street                          | SELECT r.name, r.thepath, c.cname FROM ONLY road r, real_city c WHERE (c.outline ## r.thepath);
   toyemp                          | SELECT emp.name, emp.age, emp.location, (12 * emp.salary) AS annualsal FROM emp;
! (61 rows)
  
  SELECT tablename, rulename, definition FROM pg_rules
  	ORDER BY tablename, rulename;