1

How do I select specific records if i only put one symbol in filter?

Eg:
tab:([]a:1 2 3;b:(`abc`bde;`efg`rte;`dqw`gds))
1   (`abc`bde)
2   (`efg`rte)
3   (`dqw`gds)

I want to filter on abc so only return:

1   (`abc`bde)

select from tab where b=`abc will not work.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Terry
  • 523
  • 9
  • 21
  • Possible duplicate of [How to query KDB table where one column is a list?](https://stackoverflow.com/questions/40090753/how-to-query-kdb-table-where-one-column-is-a-list) – Paul Kerrigan Jun 22 '17 at 15:08

1 Answers1

5

You can use the each-right adverb /: with the in function:

q)select from tab where `abc in/: b
a b      
---------
1 abc bde

Each-right is necessary here because table columns are vectors; so in is operating on a nested list of symbols. The exec call below shows this more clearly:

q)0N!(exec b from tab);
(`abc`bde;`efg`rte;`dqw`gds)
James Little
  • 1,964
  • 13
  • 12