X-Original-To: pgsql-patches-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E9800DA7D7 for ; Thu, 20 Oct 2005 02:19:24 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81391-06 for ; Thu, 20 Oct 2005 05:19:22 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7BB36DA688 for ; Thu, 20 Oct 2005 02:19:22 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9K5JFLE005463; Thu, 20 Oct 2005 01:19:15 -0400 (EDT) To: Christopher Kings-Lynne Cc: Patches Subject: Re: Error in ORDER BY on check constraints in psql In-reply-to: <435725A1.5070900@familyhealth.com.au> References: <435725A1.5070900@familyhealth.com.au> Comments: In-reply-to Christopher Kings-Lynne message dated "Thu, 20 Oct 2005 13:05:37 +0800" Date: Thu, 20 Oct 2005 01:19:15 -0400 Message-ID: <5462.1129785555@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/174 X-Sequence-Number: 17670 Christopher Kings-Lynne writes: > Everything is sorted by object name in \d except check > constraints for some reason. It seems it's ordering by the wrong column. > Seems like a bug to me. That was probably done deliberately, back in the day when constraints tended to have uselessly random names like "$1" --- sorting by the constraint text was more helpful. I agree that now sorting by name seems like the better thing. > Attached is the trivial patch. I think there's nothing wrong with the "ORDER BY 1" part ... it's the fact that the columns are selected in a different order than they'll be used that seems bizarre to me. I fixed it like this instead. regards, tom lane *** src/bin/psql/describe.c.orig Fri Oct 14 23:00:19 2005 --- src/bin/psql/describe.c Thu Oct 20 01:09:29 2005 *************** *** 1036,1044 **** if (tableinfo.checks) { printfPQExpBuffer(&buf, ! "SELECT " ! "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); --- 1036,1043 ---- if (tableinfo.checks) { printfPQExpBuffer(&buf, ! "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' ORDER BY 1", oid); *************** *** 1192,1199 **** for (i = 0; i < check_count; i++) { printfPQExpBuffer(&buf, _(" \"%s\" %s"), ! PQgetvalue(result2, i, 1), ! PQgetvalue(result2, i, 0)); footers[count_footers++] = pg_strdup(buf.data); } --- 1191,1198 ---- for (i = 0; i < check_count; i++) { printfPQExpBuffer(&buf, _(" \"%s\" %s"), ! PQgetvalue(result2, i, 0), ! PQgetvalue(result2, i, 1)); footers[count_footers++] = pg_strdup(buf.data); }