Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:48 AM
Ben
Guest
 
Posts: n/a
Default Are there commands to enquire about table structure?

PostgreSQL mavens, can I ask the database, in a normal database query command, or in other words,
essentially using the same environment where I'd say...

SELECT count(*) FROM mytable [WHERE myconditions_obtain];

....to get # records in my table,

o How many fields mytable has as in:
SELECT fieldcount(*) from mytable

o What the names of the fields are as in:
SELECT fieldname(n) from mytable = one name ...OR...
SELECT fieldnames() from mytable = a row per field

o What type of field "fieldname" is as in:
SELECT fieldtype(fieldnumber) from mytable ...OR...
SELECT fieldtype(fieldname) from mytable ...OR...
SELECT fieldtypes() from mytable = a row per field

o How long a field is as in:
SELECT fieldlength(fieldnumber) from mytable ...OR...
SELECT fieldlength(fieldname) from mytable
SELECT fieldlengths() from mytable = a row per field

Ideally, I envision being able to say...

SELECT fieldnames(),fieldtypes(),fieldlengths() FROM customers;

....and I might get back:

[firstname],[char],[15]
[lastname],[char],[20]
[custnum],[int],NULL
etc...

....or maybe...
SELECT fieldnames(),fieldtypes() FROM customers;

....and I might get back:

[firstname],[char(15)]
[lastname],[char(20)]
[custnum],[int]
etc...

Maybe I could even say:
SELECT fieldnames(),fieldtypes() from customers WHERE fieldnames() ilike '%name%';

....and I might get back:

[firstname],[char(15)]
[lastname],[char(20)]

....where [custnum],[int] is left out because of the WHERE clause.

I would find this kind of capability very useful for certain types of flexible table
processing I'd like to do.

Thanks for any insight into this, I appreciate any and all input.

--Ben




 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.