Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a subset of columns from table with list in kdb+/q?

Tags:

kdb

Given the following table:

time     | col1  col2  col3  ...
--------------------------------
10:53:02 | 89    89    76    ...
...

How does one select a subset of columns from this table (including the index) referenced by a list of column names i.e. cols:('col1';'col3'); Whereby the expected result would be:

time     | col1  col3
----------------------
10:53:02 | 89    89   
...

Thanks

like image 984
benjamin rossman Avatar asked Sep 03 '19 21:09

benjamin rossman


1 Answers

You could use a take (#) keyword with the each right (/:) adverb. So q will take the subset of sym and price columns from the table t and return a table with your key and your required subset of data

q)t:([time:.z.z+ 1 2];sym:`a`b;price:10 20;vol:30 40)
q)c:`sym`price
q)c#/:t
time                   | sym price
-----------------------| ---------
2019.09.05T07:56:36.069| a   10
2019.09.06T07:56:36.069| b   20
like image 79
Nicole Watterson Avatar answered Sep 29 '22 09:09

Nicole Watterson