Thread: BUG #4547: sort columns in \d

BUG #4547: sort columns in \d

From
"Ferdinand Gassauer"
Date:
The following bug has been logged online:

Bug reference:      4547
Logged by:          Ferdinand Gassauer
Email address:      gassauer@kde.org
PostgreSQL version: 8.3.5
Operating system:   any
Description:        sort columns in \d
Details:

currently the columns are sorted by attnum (not very userfriendly) instead
of attname (userfriendly)

this patch fixes this and makes the output of \d much more usable.

thank you for listening


--- describe.c.dist     2008-11-23 16:59:07.000000000 +0100
+++ describe.c  2008-11-23 16:59:28.000000000 +0100
@@ -867,7 +867,7 @@ describeOneTableDetails(const char *sche
        appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0
AND NOT a.attisdropped", oid);
        if (tableinfo.relkind == 'i')
                appendPQExpBuffer(&buf, " AND a.attrelid = i.indexrelid");
-       appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
+       appendPQExpBuffer(&buf, "\nORDER BY a.attname");

        res = PSQLexec(buf.data, false);
        if (!res)

Re: BUG #4547: sort columns in \d

From
toruvinn
Date:
On Sun, 23 Nov 2008 17:19:38 +0100, Ferdinand Gassauer <gassauer@kde.org>
wrote:
> currently the columns are sorted by attnum (not very userfriendly)
> instead
> of attname (userfriendly)
Actually, I prefer it the old way. I just like to know the column order
`SELECT *' would return (though I never use `SELECT *' myself). Not to
mention - the column order in my tables usually has some logical meaning
(result of relation design, you yourself probably don't just `throw some
columns in there' too) which would be lost otherwise.


Regards,
--
ru

Re: BUG #4547: sort columns in \d

From
Tom Lane
Date:
"Ferdinand Gassauer" <gassauer@kde.org> writes:
> currently the columns are sorted by attnum (not very userfriendly) instead
> of attname (userfriendly)

This is intentional.

> this patch fixes this and makes the output of \d much more usable.

Calling this a "bug" isn't a good way to start a discussion about it.

            regards, tom lane

Re: BUG #4547: sort columns in \d

From
"Jaime Casanova"
Date:
On Sun, Nov 23, 2008 at 12:40 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
>> this patch fixes this and makes the output of \d much more usable.
>
> Calling this a "bug" isn't a good way to start a discussion about it.
>

specially because this *fix* will lead to confusions about the order
of columns in INSERT statements, eventually you will be forced to put
column names in every INSERT statement (ie: if you start to work in an
enterprise with an already implemented postgres database)


--=20
Atentamente,
Jaime Casanova
Soporte y capacitaci=F3n de PostgreSQL
Asesor=EDa y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

Re: BUG #4547: sort columns in \d

From
Tom Lane
Date:
"Jaime Casanova" <jcasanov@systemguards.com.ec> writes:
> On Sun, Nov 23, 2008 at 12:40 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> this patch fixes this and makes the output of \d much more usable.
>>
>> Calling this a "bug" isn't a good way to start a discussion about it.

> specially because this *fix* will lead to confusions about the order
> of columns in INSERT statements,

And "SELECT *" statements.  I don't necessarily object to having some
way to list the columns alphabetically, but it shouldn't be the only
way, and probably not even the default.

            regards, tom lane

Re: BUG #4547: sort columns in \d

From
Andrew Sullivan
Date:
On Sun, Nov 23, 2008 at 05:36:13PM +0100, toruvinn wrote:

> Actually, I prefer it the old way. I just like to know the column order
> `SELECT *' would return (though I never use `SELECT *' myself). Not to

You can't know that, as a matter of SQL semantics.

A


--
Andrew Sullivan
ajs@crankycanuck.ca

Re: BUG #4547: sort columns in \d

From
Andrew Sullivan
Date:
On Mon, Nov 24, 2008 at 01:39:48AM -0500, Andrew Sullivan wrote:
>
> You can't know that, as a matter of SQL semantics.

I shouldn't reply to listmail when bone tired.  I was thinking of
rows.  Sorry.

A

--
Andrew Sullivan
ajs@crankycanuck.ca

Re: BUG #4547: sort columns in \d

From
Ferdinand Gassauer
Date:
>Calling this a "bug" isn't a good way to start a discussion about it.
sorry, didn't want to insult anyone

All your comments are certainly valid.

I had to inspect and maintain a database which was not designed by me and has
tables with some 20-30 columns - no way to understand which columns are in a
table with the actual \d
OK other way is to use a graphical client...

may be a \D which sorts alphabetically  ?

thanks for listening
--
cu
ferdinand