pg.ddx.io  pgsql-ports@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Error in ORDER BY on check constraints in psql
3+ messages / 2 participants
[nested] [flat]

* Error in ORDER BY on check constraints in psql
@ 2005-10-20 05:05 Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2005-10-20 05:19 ` Re: Error in ORDER BY on check constraints in psql Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Christopher Kings-Lynne @ 2005-10-20 05:05 UTC (permalink / raw)
  To: Patches <pgsql-patches@postgresql.org>

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.

Attached is the trivial patch.

Chris

Attachments:

describe.txt (text/plain, 927B) download Index: src/bin/psql/describe.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.127 diff -c -r1.127 describe.c *** src/bin/psql/describe.c 15 Oct 2005 02:49:40 -0000 1.127 --- src/bin/psql/describe.c 20 Oct 2005 04:58:58 -0000 *************** *** 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) --- 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 2", oid); result2 = PSQLexec(buf.data, false); if (!result2)
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: Error in ORDER BY on check constraints in psql
  2005-10-20 05:05 Error in ORDER BY on check constraints in psql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
@ 2005-10-20 05:19 ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-10-20 05:28   ` Re: Error in ORDER BY on check constraints in psql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2005-10-20 05:19 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Patches <pgsql-patches@postgresql.org>

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); }
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: Error in ORDER BY on check constraints in psql
  2005-10-20 05:05 Error in ORDER BY on check constraints in psql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2005-10-20 05:19 ` Re: Error in ORDER BY on check constraints in psql Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-10-20 05:28   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 0 replies; 3+ messages in thread

From: Christopher Kings-Lynne @ 2005-10-20 05:28 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Patches <pgsql-patches@postgresql.org>

> 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.

Even in the "$x" case, it's better to have them sorted in that order 
(ie. the order they were created...)

> 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.

Ah, the way that requires effort :)




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-10-20 05:28 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-20 05:05 Error in ORDER BY on check constraints in psql Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-10-20 05:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-10-20 05:28   ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

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