cancel
Showing results for 
Search instead for 
Did you mean: 

Why Q SQL doesn't work with "in"?

vivo
New Contributor III

I have codes as below. Why the last line would fail? How to make it work?

Thanks!

 

t:([] c1:`a`b`a`c`b`c; c2:1 1 1 2 2 2; c3:10 20 30 40 50 60);

select from t where c1 in enlist `a; // works
select from t where c1 in `a`b; // works
?[t;enlist (in;`c1;enlist `a);0b;()]; // works
?[t;enlist (in;`c1;`a`b);0b;()]; // failed

 

1 ACCEPTED SOLUTION

gyorokpeter-kx
Contributor
Contributor

The parameters to functional select are parse trees. These have a special rule for symbols and lists because a symbol can also represent a variable/column name, and a list can mean function invocation.

The rule is that enlisting a value acts as an "escape" so the symbol or list is taken at face value and not evaluated. In your 3rd example, you are enlisting the symbol so it acts as a literal symbol and not a column named "a". In the 4rd example, there is no enlist, so the list `a`b is taken as a function application, which then looks for variables or columns named a and b to perform the application. It works if you enlist the symbol list.

?[t;enlist (in;`c1;enlist`a`b);0b;()]

View solution in original post

1 REPLY 1

gyorokpeter-kx
Contributor
Contributor

The parameters to functional select are parse trees. These have a special rule for symbols and lists because a symbol can also represent a variable/column name, and a list can mean function invocation.

The rule is that enlisting a value acts as an "escape" so the symbol or list is taken at face value and not evaluated. In your 3rd example, you are enlisting the symbol so it acts as a literal symbol and not a column named "a". In the 4rd example, there is no enlist, so the list `a`b is taken as a function application, which then looks for variables or columns named a and b to perform the application. It works if you enlist the symbol list.

?[t;enlist (in;`c1;enlist`a`b);0b;()]