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
---| -----
str|
q)

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

q)`t insert enlist enlist "foo"
,0
q)t
str

How do I choose whether to make a field a symbol or string?

A q string is a vector of characters. If you need to manipulate the string, or the set of possible values the string might take is unbounded, then go with string.

Use symbol when the set of values is restricted, e.g., exchange names, or tickers. Symbols are faster for comparison operations (and that means lookup as well).

See string interning.


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.