Select char - KDB based on the column value of the char array

I have a table built like this:

tab: ([]col1:();col2:()) `tab insert (`testsym; "testchararr") 

Now I want to select the line where col2 has the value "testchararr" . I tried like this:

 select from tab where col2 = "test" 

but this always returns a 'length error.

How can I execute a query based on the value of a char array? Thanks

+4
source share
2 answers

Use "like" or an adverb. eg.

 q)select from tab where col2 like "testchararr" col1 col2 --------------------- testsym "testchararr" q)select from tab where col2~\:"testchararr" col1 col2 --------------------- testsym "testchararr" q)select from tab where col2 like "test" col1 col2 --------- q)select from tab where col2~\:"test" col1 col2 --------- 

I advise you to check the speed of each method. For additional qsql examples, both in use, see: http://www.timestored.com/b/forums/topic/string-functions-like-search-replace-regex/

+5
source

Found this out:

I need to use like instead of =

i.e.

 select from tab where col2 like "test" 
+1
source

Source: https://habr.com/ru/post/1493634/


All Articles