Search code examples
kdb

How to delete only tables in kdb?


say:

q) \a .x
`a`b

q) \f .x
`f1`f2

I need to delete only the tables a and b but not the functions. Now in this case, I can simply say delete a,b from `.x but is there a way to functionalize this?


Solution

  • You can use the following.

    q)tables[]  /get list of tables in current namespace
    `table1`table2`table3..
    
    q)parse"delete table1 from `."   /get the parse tree - needed to functionalise
    
    q)![`.;();0b;tables[]]  /combine to delete only tables
    `.
    q)tables[]
    `symbol$()
    

    using namespaces

    q)tables `.b
    `table3`table4`table5
    q){![x;();0b;tables x]} `.b
    `.b
    q)tables `.b
    `symbol$()
    

    Hope this helps

    Connor