Short answer: meta tablename

For example –

q)\l sp.q        / found in $QHOME/sp.q
q)s
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
q)

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
`symbol
q)

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

q)type exec city from s
11h
q)

See also: Type character definitions, Meta output faq.

Convert to string, then to int by applying the $ (cast) operator while passing an uppercase type character as its left argument:

q)”I” $ string `123
123
q)

Type number also works:

q)type 123
-6h
q)-6h $ string `123
123
q)

See also: string to symbol conversion faq, Datatypes and $

By applying the $ (cast) operator while passing ` (the null symbol) as its left argument:

q)` $ “foo”
`foo
q)

The cast operator also accepts an uppercase type character as its left argument:

q)”S” $ “foo”
`foo
q)

Moreover, you can convert a list of strings at once:

q)”S” $ (“foo”; “bar”; “baz”)
`foo`bar`baz
q)

To go the other way, use the string function:

q)string `foo
“foo”
q)

Since the string function is implemented as the monadic form (i.e., single argument overload) of the k function $

q)string
$:
q)

— it is also possible to write the above cast as follows:

q)($)`foo
“foo”
q)

Although we don’t recommend it, we thought you should know in case you see it in the wild.

See also: type