diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
new file mode 100644
index b2c54b5..682cf8a
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
*************** describeOneTableDetails(const char *sche
*** 1159,1165 ****
  						  "c.relpersistence\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s'\n",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
--- 1159,1165 ----
  						  "c.relpersistence\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s';",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
*************** describeOneTableDetails(const char *sche
*** 1175,1181 ****
  						  "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s'\n",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
--- 1175,1181 ----
  						  "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s';",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
*************** describeOneTableDetails(const char *sche
*** 1190,1196 ****
  						  "%s, c.reltablespace\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s'\n",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
--- 1190,1196 ----
  						  "%s, c.reltablespace\n"
  						  "FROM pg_catalog.pg_class c\n "
  		   "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
! 						  "WHERE c.oid = '%s';",
  						  (verbose ?
  						   "pg_catalog.array_to_string(c.reloptions || "
  						   "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
*************** describeOneTableDetails(const char *sche
*** 1203,1209 ****
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "%s, reltablespace\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s'",
  						  (verbose ?
  					 "pg_catalog.array_to_string(reloptions, E', ')" : "''"),
  						  oid);
--- 1203,1209 ----
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "%s, reltablespace\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s';",
  						  (verbose ?
  					 "pg_catalog.array_to_string(reloptions, E', ')" : "''"),
  						  oid);
*************** describeOneTableDetails(const char *sche
*** 1214,1220 ****
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "'', reltablespace\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s'",
  						  oid);
  	}
  	else
--- 1214,1220 ----
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "'', reltablespace\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s';",
  						  oid);
  	}
  	else
*************** describeOneTableDetails(const char *sche
*** 1223,1229 ****
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "'', ''\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s'",
  						  oid);
  	}
  
--- 1223,1229 ----
  					  "SELECT relchecks, relkind, relhasindex, relhasrules, "
  						  "reltriggers <> 0, relhasoids, "
  						  "'', ''\n"
! 						  "FROM pg_catalog.pg_class WHERE oid = '%s';",
  						  oid);
  	}
  
*************** describeOneTableDetails(const char *sche
*** 1265,1271 ****
  	{
  		printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
  		/* must be separate because fmtId isn't reentrant */
! 		appendPQExpBuffer(&buf, ".%s", fmtId(relationname));
  
  		res = PSQLexec(buf.data, false);
  		if (!res)
--- 1265,1271 ----
  	{
  		printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
  		/* must be separate because fmtId isn't reentrant */
! 		appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));
  
  		res = PSQLexec(buf.data, false);
  		if (!res)
*************** describeOneTableDetails(const char *sche
*** 1299,1305 ****
  		appendPQExpBuffer(&buf, ",\n  a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
  	appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
  	appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
! 	appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
  
  	res = PSQLexec(buf.data, false);
  	if (!res)
--- 1299,1305 ----
  		appendPQExpBuffer(&buf, ",\n  a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
  	appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
  	appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
! 	appendPQExpBuffer(&buf, "\nORDER BY a.attnum;");
  
  	res = PSQLexec(buf.data, false);
  	if (!res)
*************** describeOneTableDetails(const char *sche
*** 1394,1400 ****
  		PGresult   *result;
  
  		printfPQExpBuffer(&buf,
! 			  "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true)",
  						  oid);
  		result = PSQLexec(buf.data, false);
  		if (!result)
--- 1394,1400 ----
  		PGresult   *result;
  
  		printfPQExpBuffer(&buf,
! 			  "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
  						  oid);
  		result = PSQLexec(buf.data, false);
  		if (!result)
*************** describeOneTableDetails(const char *sche
*** 1509,1515 ****
  					  "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
  						  "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
  		  "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
! 						  "AND i.indrelid = c2.oid",
  						  oid);
  
  		result = PSQLexec(buf.data, false);
--- 1509,1515 ----
  					  "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
  						  "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
  		  "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
! 						  "AND i.indrelid = c2.oid;",
  						  oid);
  
  		result = PSQLexec(buf.data, false);
*************** describeOneTableDetails(const char *sche
*** 1580,1586 ****
  			printfPQExpBuffer(&buf,
  							  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
  							  "FROM pg_catalog.pg_rewrite r\n"
! 			"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 1580,1586 ----
  			printfPQExpBuffer(&buf,
  							  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
  							  "FROM pg_catalog.pg_rewrite r\n"
! 			"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 1637,1643 ****
  								  "  LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
  			appendPQExpBuffer(&buf,
  							  "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
! 			  "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 1637,1643 ----
  								  "  LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
  			appendPQExpBuffer(&buf,
  							  "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
! 			  "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 1717,1723 ****
  							  "SELECT r.conname, "
  							  "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
  							  "FROM pg_catalog.pg_constraint r\n"
! 				   "WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 1717,1723 ----
  							  "SELECT r.conname, "
  							  "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
  							  "FROM pg_catalog.pg_constraint r\n"
! 				   "WHERE r.conrelid = '%s' AND r.contype = 'c'\nORDER BY 1;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 1748,1754 ****
  							  "SELECT conname,\n"
  				 "  pg_catalog.pg_get_constraintdef(r.oid, true) as condef\n"
  							  "FROM pg_catalog.pg_constraint r\n"
! 					"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 1748,1754 ----
  							  "SELECT conname,\n"
  				 "  pg_catalog.pg_get_constraintdef(r.oid, true) as condef\n"
  							  "FROM pg_catalog.pg_constraint r\n"
! 					"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 1779,1785 ****
  						   "SELECT conname, conrelid::pg_catalog.regclass,\n"
  				 "  pg_catalog.pg_get_constraintdef(c.oid, true) as condef\n"
  							  "FROM pg_catalog.pg_constraint c\n"
! 				   "WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 1779,1785 ----
  						   "SELECT conname, conrelid::pg_catalog.regclass,\n"
  				 "  pg_catalog.pg_get_constraintdef(c.oid, true) as condef\n"
  							  "FROM pg_catalog.pg_constraint c\n"
! 				   "WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 1812,1818 ****
  								  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
  								  "ev_enabled\n"
  								  "FROM pg_catalog.pg_rewrite r\n"
! 								  "WHERE r.ev_class = '%s' ORDER BY 1",
  								  oid);
  			}
  			else
--- 1812,1818 ----
  								  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
  								  "ev_enabled\n"
  								  "FROM pg_catalog.pg_rewrite r\n"
! 								  "WHERE r.ev_class = '%s' ORDER BY 1;",
  								  oid);
  			}
  			else
*************** describeOneTableDetails(const char *sche
*** 1821,1827 ****
  								  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
  								  "'O'::char AS ev_enabled\n"
  								  "FROM pg_catalog.pg_rewrite r\n"
! 								  "WHERE r.ev_class = '%s' ORDER BY 1",
  								  oid);
  			}
  			result = PSQLexec(buf.data, false);
--- 1821,1827 ----
  								  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
  								  "'O'::char AS ev_enabled\n"
  								  "FROM pg_catalog.pg_rewrite r\n"
! 								  "WHERE r.ev_class = '%s' ORDER BY 1;",
  								  oid);
  			}
  			result = PSQLexec(buf.data, false);
*************** describeOneTableDetails(const char *sche
*** 1927,1933 ****
  							  "  (SELECT 1 FROM pg_catalog.pg_depend d "
  							  "   JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
  							  "   WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
! 		appendPQExpBuffer(&buf, "\nORDER BY 1");
  
  		result = PSQLexec(buf.data, false);
  		if (!result)
--- 1927,1933 ----
  							  "  (SELECT 1 FROM pg_catalog.pg_depend d "
  							  "   JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
  							  "   WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
! 		appendPQExpBuffer(&buf, "\nORDER BY 1;");
  
  		result = PSQLexec(buf.data, false);
  		if (!result)
*************** describeOneTableDetails(const char *sche
*** 2035,2041 ****
  							  "SELECT s.srvname\n"
  							  "FROM pg_catalog.pg_foreign_table f,\n"
  							  "     pg_catalog.pg_foreign_server s\n"
! 							  "WHERE f.ftrelid = %s AND s.oid = f.ftserver",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
--- 2035,2041 ----
  							  "SELECT s.srvname\n"
  							  "FROM pg_catalog.pg_foreign_table f,\n"
  							  "     pg_catalog.pg_foreign_server s\n"
! 							  "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
  							  oid);
  			result = PSQLexec(buf.data, false);
  			if (!result)
*************** describeOneTableDetails(const char *sche
*** 2053,2059 ****
  		}
  
  		/* print inherited tables */
! 		printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno", oid);
  
  		result = PSQLexec(buf.data, false);
  		if (!result)
--- 2053,2059 ----
  		}
  
  		/* print inherited tables */
! 		printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno;", oid);
  
  		result = PSQLexec(buf.data, false);
  		if (!result)
*************** add_tablespace_footer(printTableContent
*** 2215,2221 ****
  			initPQExpBuffer(&buf);
  			printfPQExpBuffer(&buf,
  							  "SELECT spcname FROM pg_catalog.pg_tablespace\n"
! 							  "WHERE oid = '%u'", tablespace);
  			result = PSQLexec(buf.data, false);
  			if (!result)
  				return;
--- 2215,2221 ----
  			initPQExpBuffer(&buf);
  			printfPQExpBuffer(&buf,
  							  "SELECT spcname FROM pg_catalog.pg_tablespace\n"
! 							  "WHERE oid = '%u';", tablespace);
  			result = PSQLexec(buf.data, false);
  			if (!result)
  				return;
*************** listDbRoleSettings(const char *pattern,
*** 2424,2430 ****
  									   NULL, "pg_roles.rolname", NULL, NULL);
  		processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
  							  NULL, "pg_database.datname", NULL, NULL);
! 		appendPQExpBufferStr(&buf, "ORDER BY role, database");
  	}
  	else
  	{
--- 2424,2430 ----
  									   NULL, "pg_roles.rolname", NULL, NULL);
  		processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
  							  NULL, "pg_database.datname", NULL, NULL);
! 		appendPQExpBufferStr(&buf, "ORDER BY role, database;");
  	}
  	else
  	{
*************** describeOneTSParser(const char *oid, con
*** 3170,3176 ****
  					  "   p.prslextype::pg_catalog.regproc, \n"
  				  "   pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
  					  " FROM pg_catalog.pg_ts_parser p \n"
! 					  " WHERE p.oid = '%s' \n",
  					  gettext_noop("Start parse"),
  					  gettext_noop("Method"),
  					  gettext_noop("Function"),
--- 3170,3176 ----
  					  "   p.prslextype::pg_catalog.regproc, \n"
  				  "   pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
  					  " FROM pg_catalog.pg_ts_parser p \n"
! 					  " WHERE p.oid = '%s';",
  					  gettext_noop("Start parse"),
  					  gettext_noop("Method"),
  					  gettext_noop("Function"),
*************** describeOneTSConfig(const char *oid, con
*** 3531,3537 ****
  	 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
  					  "WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
  					  "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
! 					  "ORDER BY 1",
  					  gettext_noop("Token"),
  					  gettext_noop("Dictionaries"),
  					  oid);
--- 3531,3537 ----
  	 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
  					  "WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
  					  "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
! 					  "ORDER BY 1;",
  					  gettext_noop("Token"),
  					  gettext_noop("Dictionaries"),
  					  oid);
