In KDB Q, how can I select the last letter of a symbol?

Viewed 263

Say I have a table with an enumerated symbol column with values:

sym
_ _ _ _ 
AAPL
MSFT
INTC

I'm trying to select just the rows where the last letter of the symbol is C.

I've selecting against last string sym and -1#string sym, but I get an incompatible list length error every time.

What am I doing wrong?

2 Answers

The keyword like works for symbols as well as strings so no need to cast to string if you're trying to pattern match

q)select from ([]sym:`AAPL`MSFT`INTC`ABC) where sym like"*C"
sym
----
INTC
ABC

Does this work?

q)t: ([] sym: `AAPL`MSFT`INTC)
q)t
sym 
----
AAPL
MSFT
INTC
q)select last each string sym from t
sym
---
L  
T  
C  
Related