How do I use a for loop with an if statement in a kdb/Q table?

102 Views Asked by At

I am new to kdb/Q. I've used Python in the past, and am trying to find out how I can traverse a kdb table using the equivalent of a for loop. I have a table called SymbolList that looks like this:

Symbol Start Date End Date
X 2022.12.09
Y 2018.10.27 2022.12.08
Z 2018.04.04 2018.10.26
A 2014.10.05 2018.04.03

I am trying to take each row and plug it into a different function (already written) that spits out a boolean, and if the output of this boolean function returns True, the loop ends.

Can anyone help me with how I can do this? Thanks in advance.

1

There are 1 best solutions below

2
cillianreilly On BEST ANSWER

Given your comment on what your use case is (I have also sanitised your column names - you should avoid spaces in column names):

q)first select from SymbolList where 2020.01.01 within(sd;ed)
sym| `Y
sd | 2018.10.27
ed | 2022.12.08

Replace 2020.01.01 with your given date.

If you want a tabular result instead:

q)select[1] from SymbolList where 2020.01.01 within(sd;ed)
sym sd         ed
-------------------------
Y   2018.10.27 2022.12.08