4

I have a table:

t3:([]a:2 3 4;b:`CA`AB`)

I have a query:

select from t3 where b in ?[a=2;`CA`AB;`AB]

Bong... it give me `length error.

But these works:

select from t3 where b in ?[a=2;`CA;`AB] 

select from t3 where b in `CA`AB

Cannot think of where goes wrong? Please help... Thanks.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Lance LI
  • 113
  • 3
  • 9
  • Thank you, but I think I didn't describe it clearly - I am trying to get different data out based on different values in one specific column. Say for this table: t:([]dt:2016.10.01 2016.10.05 2016.10.08 2016.10.20;flag:`AB`AC`BC`CD;val:1 4 2 3) I want to query rows with flag in `AB`AC if date is before 2016.10.10; otherwise I want query out flag in `CD. is that possible doing this check within one where clause? – Lance LI Oct 26 '16 at 08:04

1 Answers1

2

The length error is caused by using lists of differing lengths in a vector conditional statement - see http://code.kx.com/q/ref/lists/#vector-conditional for more details. Your other statement works because the two output arguments are atomic.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Paul Kerrigan
  • 465
  • 5
  • 12
  • Here's an example of what you could do to get the result you're looking for: ```d:t3[`a]!{$[x=2;`AB`CA;`]}'[t3`a]; select from t3 where b in' d a``` – Paul Kerrigan Oct 26 '16 at 08:05
  • Thanks that works. but how can I do that within one where clause... say this one works: select from t where flag in ?[dt<2016.10.10;`AB;`CD]. it also check for each value of "dt" right.. just return is atom. Why change return from atom to symbol list then query is broken? – Lance LI Oct 26 '16 at 08:34
  • The vector conditional works by replacing items of the y argument with the items of z when the x argument evaluates false - in the event that you've used an atom they're repeated. (The vector conditional will treat your atom as though it were a list of equivalent length to the argument boolean list) – Paul Kerrigan Oct 26 '16 at 08:52
  • In order to do this in one line you can just put the lambda into the where clause - I used a dictionary to try to make it a little clearer. ```select from t3 where b in' {$[x=2;`CA`AB;`AB]}'[a]``` will get you the result you want. – Paul Kerrigan Oct 26 '16 at 10:49