Sender: owner-postgres95@postgres.Berkeley.EDU
X-Return-Path: andrew_yu
Received: from eden.CS.Berkeley.EDU (eden.CS.Berkeley.EDU [128.32.37.56]) by nobozo.CS.Berkeley.EDU (8.6.10/8.6.3) with ESMTP id UAA19789 for <postgres95@postgres.Berkeley.EDU>; Fri, 10 Nov 1995 20:29:08 -0800
Received: (andrew@localhost) by eden.CS.Berkeley.EDU (8.6.10/8.6.3) id UAA23245; Fri, 10 Nov 1995 20:28:59 -0800
Date: Fri, 10 Nov 1995 20:28:59 -0800
From: "Andrew K. Yu" <andrew@postgres.Berkeley.EDU>
Message-Id: <199511110428.UAA23245@eden.CS.Berkeley.EDU>
To: e8903122@student.tuwien.ac.at, postgres95@postgres.Berkeley.EDU
Subject: Re:  Postgres 95 PL 14 Bug Report
Resent-To: postgres95-redist
Resent-Date: Fri, 10 Nov 95 20:29:09 -0800
Resent-From: pglite
Resent-XMts: smtp


> This is a problem with the \d command of psql.
> If you are using the \d <relname> command of psql, you get a list of attributes
> which isn't ordered as expected to use in a insert into ... command.

This is not really a bug. It's not documented to have such behavior --
although I agree it would be more intuitive to expect it as such.

You could also have specified the column name in the insert statement and
ordering wouldn't matter:

INSERT INTO foo (x, y) values (1, 2);
INSERT INTO foo (y, x) values (2, 1);

> DECLARE myportal CURSOR FOR
> SELECT a.attname, t.typname, a.attlen
>   FROM pg_class c, pg_attribute a, pg_type t 
>     WHERE c.relname = 'mytest'
>     and a.attnum > 0
>     and a.attrelid = c.oid
>     and a.atttypid = t.oid
>   ORDER BY attname
> 
> I think, the 'ORDER BY attname' is the problem. I can't figure out, what will
> be approbiate for this, perhaps there will be someone who is familiar with the
> internal structures to fix this in some minutes.

you want them 'ORDER BY attnum' instead.


there is also another trick which is often useful:

select * from <table name> where 1 = 0;

since the qualification is false, you'll get back no rows except the banner
which list the columns in order.

-andrew



===============================================================================
  To unsubscribe from the Postgres95 mailing list, send mail with the subject
  line "DEL" to "postgres95-request@postgres.Berkeley.EDU". 
============  URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres95/  ===========
