Entries in type string (2)

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  
-----
"foo"
q)meta t
c  | t f a
---| -----
str| C    
q)

Beware: if the column is emptied, it loses its type. See this related faq.

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.