cjm2671
cjm2671

Reputation: 19486

How do I return columns starting with a particular prefix in KDB?

Say for example I have a table:

q)([] aa: til 5; ab: til 5; bb: til 5)

aa ab bb
--------
0  0  0
1  1  1
2  2  2
3  3  3
4  4  4

Is there a simple way of querying for just the columns that begin with a?

Upvotes: 0

Views: 234

Answers (2)

terrylynch
terrylynch

Reputation: 13657

If your table is in-memory and unkeyed then take (#) can also do it for you:

{where[c!(c:cols x)like"a*"]#x}t

But Matts solution is more general and thus more useful!

Upvotes: 1

Matt Moore
Matt Moore

Reputation: 2800

You can use functional select

?[t;();0b;{x!x}cols[t] where cols[t] like "a*"]

https://code.kx.com/q/basics/funsql/

Upvotes: 3

Related Questions