An easier way to get the type of a column?

Поиск
Список
Период
Сортировка
От Paul Sheer
Тема An easier way to get the type of a column?
Дата
Msg-id 199910051917.VAA11928@mail450.icon.co.za
обсуждение исходный текст
Список pgsql-general
Hi there,

I need to return the type of a column, but can't find a function to do
this. Ideally i would like to
    select typename(my_column) from my_table;

is there some such-like function?

currently I use:

def get_column_types (table, db):
    r = {}
    tableoid = db.query (
    "SELECT typrelid FROM pg_type WHERE (typname = '" + table + "') "
    ).getresult ()[0][0]
    q = db.query (
    "SELECT attname, atttypid FROM pg_attribute WHERE (attrelid = " + `tableoid` + ") "
    ).getresult ()
    a = []
    for attr in q:
    a.append (attr[0])
    r[attr[0]] = db.query (
        "SELECT typname FROM pg_type WHERE (typelem = " + `attr[1]` + ") "
    ).getresult ()[0][0][1:]
    return a, r

which is a real pain

many thanks for any help

-paul

--
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.3i

mQCNAzdiRpAAAAEEANPUPC/Lrs4OCJOjWaIWaCYTzTIY1p73uPY+8ZOJH5fc4QNp
IAX+EFQ/yZ3RMOLg8yy++HufzBwDoePO4W0MKwyVFCcNIIjsY6JCXWdbpQXsY1LL
OASlGexQnEQ4mfc7ThOAKWSgPyiMv5vDJ6S0EL8rdIFL7fVv56BAxnN042FRAAUR
tCJQYXVsIFNoZWVyIDxwc2hlZXJAb2JzaWRpYW4uY28uemE+iQCVAwUQN2JGkKBA
xnN042FRAQF5CAP/Y0TaguqCpYiTEBHxZPpT/dliInVRBzryi4gdlgX6CCLDRRGH
ATP4ac8aiATegc4ev4+vcdn4fBwc6fQ2AP6hd25ZI93vShxztM/bQlGWy0zp79Uo
+69uGdJhdvgYpIsTCqppM/yjeXAJEqq5TG2Gy4pqHY235rspmeA/fX7kgIo=
=aX4m
-----END PGP PUBLIC KEY BLOCK-----

Cellular . . . +27 83 604 0615 . . . .  Land . . . +27 21 761 7224
Obsidian Systems . . . .  Linux installations, support, networking
info@obsidian.co.za . . . . . . . . . .  Tel  . .  +27 11 792 6500
http://www.obsidian.co.za  . . . . . . . Fax . . . +27 11 792 6522
L I N U X . . . . . . . . . . . . . The Choice of a GNU Generation


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

Предыдущее
От: "Ing. Arturo de la Torre"
Дата:
Сообщение: Some information about JDBC
Следующее
От: Michael Simms
Дата:
Сообщение: Re: [GENERAL] leaking FD's ?