Search code examples
kdb

How do I parameterise the column list in KDB?


I have a number of repetitive queries:

select lR, e10, e25, vr from z

Is there a way I can do something like:

features: `lR`e10`e25`vr

select features from z

Solution

  • You could use # like so:

    `lR`e10`e25`vr#z
    

    NB: The left argument here must be a list so to select a single column use the following:

    enlist[`vr]#z
    

    Example:

    q)t:([]a:`a`b`c;b:til 3;c:0b);
    q)`a`b#t
    a b
    ---
    a 0
    b 1
    c 2