Entries in meta (2)

How can I find the data type of a given table column?

Short answer: meta tablename

For example -

q)\l sp.q        / found in $QHOME/sp.q
s | name  status city
--| -------------------
s1| smith 20     london
s2| jones 10     paris
s3| blake 30     paris
s4| clark 20     london
s5| adams 30     athens
q)meta s
c     | t f a
------| -----
s     | s
name  | s
status| i
city  | s

The output of meta is a kdb table, where columns c and t indicate the column name and data type, respectively.

The key the provides an alternate method:

q)key exec city from s

If you need the type code, use the type function:

q)type exec city from s

See also: Type character definitions, Meta output faq.

Is the output of meta available for use in my program?

Yes. meta's result is an ordinary q table:

$ rlwrap q sp.q
KDB+ 2.7 2011.02.16 Copyright © 1993-2011 Kx Systems
q)type meta sp
q)meta sp
c  | t f a
---| -----
s  | s s
p  | s p
qty| i
q)cols meta sp
q)meta meta sp
c| t f a
-| -----
c| s
t| c
f| s
a| s