4

I'm able to create a kdb+ table with atom types eg.

trade:([]time:`time$();sym:`symbol$();price:`float$();size:`int$())

Is it possible to create an empty table with a character vector instead? Appreciate any help/examples I can get. My knowledge of Q is quite poor

qwerty
  • 3,801
  • 2
  • 28
  • 43

2 Answers2

4

no, not really

support for "nested" types (of which "string column", i.e. list of list of char, is one) is fairly limited in q; in particular, there's no way to strongly type an empty nested list

Aaron Davies
  • 1,190
  • 1
  • 11
  • 17
2
t: ([] time: `time$(); chr: `char$())

t, ([] time: enlist 09:30:00.001; chr: enlist"abcd")

Nested types are in fact well supported, I've had tables where column entries are themselves tables.

Yike Lu
  • 1,023
  • 11
  • 13
  • Thanks, but neither "time$" or "char$" work on on my installation (kdb 2.8). Which release do you work with? – qwerty May 23 '12 at 04:38
  • 1
    Oh I know what happened, the markdown mangled it, it's supposed to be backtick time. Let me see if I can figure out the proper edit. – Yike Lu May 24 '12 at 21:35
  • Also, I realized the above might be referring to the ability to do this in splayed/partition/segmented tables, which is true to some extent. No limitation applies to nesting for in memory or simply saved tables. See http://code.kx.com/wiki/JB:KdbplusForMortals/splayed_tables#1.2.0.2_Limitations_of_Splaying – Yike Lu May 24 '12 at 21:52
  • 1
    @yike-lu: those aren't the same type -- `chr` in the empty table is a vector of character, i.e. a column where each datapoint is a single character. `chr` in the result of the comma statement is a list of list of character, (aka list of string), i.e. a column where each datapoint is a string. consider the difference between `meta t` and `meta t, ([] time: enlist 09:30:00.001; chr: enlist"abcd")` -- `chr` is type `c` in the first, and type `C` in the second. – Aaron Davies Jul 30 '12 at 13:33
  • @AaronDavies: I see what you are saying. It's true, but my code shows that one can create such a column and then insert a `C` type into it later. – Yike Lu Jul 31 '12 at 18:18
  • that's something of a quirk of the type system. try either of the following to see the difference: `\`t upsert (09:30:00.001;"abcd")` (throws `'type`); `t,: ([] time: enlist 09:30:00.001; chr: enlist"abcd")` (throws `'type`); `t: ([] time: enlist .z.T; chr: enlist" "); meta t, ([] time: enlist 09:30:00.001; chr: enlist"abcd")` (shows that `chr` has now lost its type information and become a general list). – Aaron Davies Aug 01 '12 at 15:08
  • This domain seems full of quirks... `meta ([] time: enlist 09:30:00.001; chr: enlist"abcd"), ([] time: enlist .z.T; chr: enlist"aoeu")` gives type `C` but the moment you insert a single char, it gives general type. But my point was that whether this matters depends on the problem to be solved. Edit: I see what you're saying with strong typing - one could have inferred that this was what the OP wanted. I had originally thought you meant nested types in general inside tables were not supported. – Yike Lu Aug 03 '12 at 00:29