How do I declare a table column of type string (not symbol!)?

Declare it without a type as follows:

q)t: ([] str: ())
q)meta t
c  | t f a
---| -----

A the type of a column defined as () is determined when the first row is inserted:

q)`t insert enlist enlist "foo"

Given a value, how do I get the null of that value’s type?

We take advantage of a property of q’s indexing: If you request an item from a list (or a dictionary, for that matter) using an index that is out of range, q returns the null item for the list’s type.

q)x: 1 2 3
q)x 3

Thus, we can take the item whose corresponding null we want, make a list from it, and then access that list with an out-of-range index:

q)NullOf: {[item] enlist[item] 1}
q)NullOf 1
q)(::) ~ NullOf {x*x}
q)null NullOf (.z.D; 1e; ” “; type “foo”)

Remember, there is no null list. If you pass a list to NullOf, you get the empty list of the corresponding type:

q)NullOf 1 2 3

See also: .Q.ty

This work is licensed under a Creative Commons License.
The views and opinions expressed herein are those of the authors and do not necessarily reflect those of any other person or legal entity.
Kdb+ is the registered trademark of Kx Systems, Inc.