Search code examples
kdb

insert string with special characters into KDB+


What type should I use to create a table in KDB+ and insert a string with special charcters: spaces, #, -, etc. - it looks like KDB+ treat all these and similar characters specially, because when I create a table like this:

t: ([] str: ())

And insert the string "abc # efgf - ABC.FS #.... TEST TEST" - long string with different characters, including spaces, - and # like this:

`t insert "abc # efgf - ABC.FS #.... TEST            TEST"

KDB returns type exception.


Solution

  • Your problem here doesn't come from the special characters, it comes from the fact that a string is a list of characters. You need to use enlist to insert the string as a single element into the table.

    In fact, this case is a bit atypical because you only have one column in the table, so you actually need to use enlist twice, as kdb expects a list of column data as the second argument in insert. So for this table use

    `t insert enlist enlist "blah blah # # #"
    

    If you had a table with more than one column, then you only need one enlist for the string, e.g.

    t:([]id:(); str:())
    `t insert (1; enlist "blah blah # # #")