Describe question

2007-03-27 Thread Olaf Stein
Hi All,

Is there a way to influence the order in which columns are returned in a
describe table statement. Basically I want the same order that I get in the
mysql client (Field, Type, Null, etc) in a little script I am writing, so I
can use the Column headers dynamically.

Thanks
Olaf


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Describe question

2007-03-27 Thread Rolando Edwards
Instead of just saying 'desc tbl-name;'
Try using information_schema.columns

mysql desc information_schema.columns;
+--+--+--+-+-+---+
| Field| Type | Null | Key | Default | Extra |
+--+--+--+-+-+---+
| TABLE_CATALOG| varchar(512) | YES  | | NULL|   |
| TABLE_SCHEMA | varchar(64)  | NO   | | |   |
| TABLE_NAME   | varchar(64)  | NO   | | |   |
| COLUMN_NAME  | varchar(64)  | NO   | | |   |
| ORDINAL_POSITION | bigint(21)   | NO   | | 0   |   |
| COLUMN_DEFAULT   | varchar(64)  | YES  | | NULL|   |
| IS_NULLABLE  | varchar(3)   | NO   | | |   |
| DATA_TYPE| varchar(64)  | NO   | | |   |
| CHARACTER_MAXIMUM_LENGTH | bigint(21)   | YES  | | NULL|   |
| CHARACTER_OCTET_LENGTH   | bigint(21)   | YES  | | NULL|   |
| NUMERIC_PRECISION| bigint(21)   | YES  | | NULL|   |
| NUMERIC_SCALE| bigint(21)   | YES  | | NULL|   |
| CHARACTER_SET_NAME   | varchar(64)  | YES  | | NULL|   |
| COLLATION_NAME   | varchar(64)  | YES  | | NULL|   |
| COLUMN_TYPE  | longtext | NO   | | |   |
| COLUMN_KEY   | varchar(3)   | NO   | | |   |
| EXTRA| varchar(20)  | NO   | | |   |
| PRIVILEGES   | varchar(80)  | NO   | | |   |
| COLUMN_COMMENT   | varchar(255) | NO   | | |   |
+--+--+--+-+-+---+
19 rows in set (0.00 sec)

The ORDINAL_POSITION column tells you the order by which a column is listed.

Try doing this:

SELECT ordinal_position,column_name from information_schema.columns
where table_schema = '...' and table_name = '...' order by ordinal_position;

You could coerce the order to be whatever you want it to be.
But, this should be a good starting for you. Have fun with it !!!


- Original Message -
From: Olaf Stein [EMAIL PROTECTED]
To: MySql mysql@lists.mysql.com
Sent: Tuesday, March 27, 2007 10:15:47 AM (GMT-0500) Auto-Detected
Subject: Describe question

Hi All,

Is there a way to influence the order in which columns are returned in a
describe table statement. Basically I want the same order that I get in the
mysql client (Field, Type, Null, etc) in a little script I am writing, so I
can use the Column headers dynamically.

Thanks
Olaf


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]