From: | Paul Sheer <psheer(at)icon(dot)co(dot)za> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | An easier way to get the type of a column? |
Date: | 1999-10-05 19:21:33 |
Message-ID: | 199910051917.VAA11928@mail450.icon.co.za |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)obsidian(dot)co(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Frederic.Boucher | 1999-10-05 22:07:46 | Foreign Key |
Previous Message | Michael Simms | 1999-10-05 19:05:57 | Re: [GENERAL] leaking FD's ? |