Search code examples
kdb

adding special character to Kdb table?


I would like to add a forward slash in a field name in a table:

tab:([] yes/no:`yes`yes`no;num: 1 2 3);

I tried using `$"yes/no": but didnt work. any input?


Solution

  • Create a dictionary and use flip to create a table:

    q)columns:(`$"yes/no";`num)
    q)columnValues:(`yes`yes`no;1 2 3)
    q)tab:flip columns!columnValues
    q)tab
    yes/no num
    ----------
    yes    1
    yes    2
    no     3
    

    Note that it is not good practice to name columns in this manner (you lose the ability to use qSQL) but can still access the columns by using a functional select:

    q)select yes/no from tab
    '/
      [0]  select yes/no from tab
                     ^
    q)?[tab;();0b;enlist[`$"yes/no"]!enlist[`$"yes/no"]]
    yes/no
    ------
    yes
    yes
    no