Are there commands to enquire about table structure?

Поиск
Список
Период
Сортировка
От Ben
Тема Are there commands to enquire about table structure?
Дата
Msg-id b26aca210516c97d8f584b00d85acac6@news.teranews.com
обсуждение исходный текст
Список pgsql-general
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


В списке pgsql-general по дате отправления:

Предыдущее
От: Matthew Jones
Дата:
Сообщение: Creating 'global' functions.
Следующее
От: tabai@lycos.es (tabai)
Дата:
Сообщение: About Privileges