pg.ddx.io  pgsql-ports@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Cc: Patches <pgsql-patches@postgresql.org>
Subject: Re: Error in ORDER BY on check constraints in psql
Date: Thu, 20 Oct 2005 01:19:15 -0400
Message-ID: <5462.1129785555@sss.pgh.pa.us> (raw)
In-Reply-To: <435725A1.5070900@familyhealth.com.au>
References: <435725A1.5070900@familyhealth.com.au>

Christopher Kings-Lynne <chriskl@familyhealth.com.au> writes:
> Everything is sorted by object name in \d <table> 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

inline patch 1: src/bin/psql/describe.c (+4/-5 lines) download inline-1.patch*** 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); }

view thread (3+ messages)  latest in thread

Message-ID: <5462.1129785555@sss.pgh.pa.us>
Permalink:  ../5462.1129785555@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5462.1129785555@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-ports@postgresql.org
  Cc: tgl@sss.pgh.pa.us, chriskl@familyhealth.com.au, pgsql-patches@postgresql.org
  Subject: Re: Error in ORDER BY on check constraints in psql
  In-Reply-To: <5462.1129785555@sss.pgh.pa.us>
  References: <435725A1.5070900@familyhealth.com.au> <5462.1129785555@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox