This patch makes \d on tables and views sort fk constraints, triggers
and rules alphabetically in the output. This makes it the same as for
indexes and stops the irritating random or reverse ordering it currently
has.
Chris
Index: src/bin/psql/describe.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v
retrieving revision 1.112
diff -c -r1.112 describe.c
*** src/bin/psql/describe.c 22 Feb 2005 04:40:55 -0000 1.112
--- src/bin/psql/describe.c 14 Mar 2005 07:45:01 -0000
***************
*** 959,965 ****
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'",
oid);
result = PSQLexec(buf.data, false);
if (!result)
--- 959,965 ----
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)
***************
*** 1040,1046 ****
"pg_catalog.pg_get_constraintdef(r.oid, true), "
"conname\n"
"FROM pg_catalog.pg_constraint r\n"
! "WHERE r.conrelid = '%s' AND r.contype = 'c'",
oid);
result2 = PSQLexec(buf.data, false);
if (!result2)
--- 1040,1046 ----
"pg_catalog.pg_get_constraintdef(r.oid, true), "
"conname\n"
"FROM pg_catalog.pg_constraint r\n"
! "WHERE r.conrelid = '%s' AND r.contype = 'c' ORDER BY 1",
oid);
result2 = PSQLexec(buf.data, false);
if (!result2)
***************
*** 1058,1064 ****
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'",
oid);
result3 = PSQLexec(buf.data, false);
if (!result3)
--- 1058,1064 ----
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' ORDER BY 1",
oid);
result3 = PSQLexec(buf.data, false);
if (!result3)
***************
*** 1082,1088 ****
" OR NOT EXISTS"
" (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'))",
oid);
result4 = PSQLexec(buf.data, false);
if (!result4)
--- 1082,1089 ----
" OR NOT EXISTS"
" (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'))"
! " ORDER BY 1",
oid);
result4 = PSQLexec(buf.data, false);
if (!result4)
***************
*** 1103,1109 ****
"SELECT conname,\n"
" pg_catalog.pg_get_constraintdef(oid, true) as condef\n"
"FROM pg_catalog.pg_constraint r\n"
! "WHERE r.conrelid = '%s' AND r.contype = 'f'",
oid);
result5 = PSQLexec(buf.data, false);
if (!result5)
--- 1104,1110 ----
"SELECT conname,\n"
" pg_catalog.pg_get_constraintdef(oid, true) as condef\n"
"FROM pg_catalog.pg_constraint r\n"
! "WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
oid);
result5 = PSQLexec(buf.data, false);
if (!result5)