cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform a pattern matching operation on a long data type in

A_L_V_
New Contributor
How to perform a pattern matching operation on a long data type in Kdb?

All of the following give me a `type error:
select instrument from Table where time=14201%
select instrument from Table where time=14201*
select instrument from Table where time=`14201%
select instrument from Table where time="14201*"
select instrument from Table where time=like"14201*"
select instrument from Table where time like"14201*"
select instrument from Table where time like 14201*
selec instrument from Table where time like '14201%'
select instrument from Table where time like '14201%'
select instrument from Table where time like 14201*
select instrument from Table where time like "14201*"
select instrument from Table where time like "14201*       
select instrument from Table where time like"14201*"

These work:
select instrument from Table where time=1418234533892319745
select instrument from Table where instrument like "6E*"

These do not work either:
select instrument from Table where time > 124400000
select instrument from Table where time > 124400
select instrument from Table where time < 1    
select instrument from Table where time < 1 

Some good resource I found:
http://www.timestored.com/b/forums/topic/string-functions-like-search-replace-regex/
http://www.kx.com/q/d/kdb+1.htm
2 REPLIES 2

manni_patel
New Contributor

see http://code.kx.com/wiki/Reference/like

it only works with strings/symbols. Out of the box regex is pretty
simple, as you've already discovered.

if you really want to match a non-string column with a regex with
like, you have to stringify it:

select from x where string[time] like "*08:00*"

Although I think in most cases I'm sure there's a far more efficient
way of doing it!!

kuentang
New Contributor

The column time is from type long so pattern matching cannot be used directly here. You can use within here

 

q) select instrument  from Table where time within 1420000000000000000 1430000000000000000

 

If you really want to use pattern matching then cast time to string first

 

q) select instrument from  Table where string[time] like “14201*”

 

HTH,

 

Kim

 

 

Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von A.L.V.
Gesendet: Donnerstag, 26. Februar 2015 23:17
An: personal-kdbplus@googlegroups.com
Betreff: [personal kdb+] How to perform a pattern matching operation on a long data type in Kdb?

 

How to perform a pattern matching operation on a long data type in Kdb?

All of the following give me a `type error:
select instrument from Table where time=14201%
select instrument from Table where time=14201*
select instrument from Table where time=`14201%
select instrument from Table where time="14201*"
select instrument from Table where time=like"14201*"
select instrument from Table where time like"14201*"
select instrument from Table where time like 14201*
selec instrument from Table where time like '14201%'
select instrument from Table where time like '14201%'
select instrument from Table where time like 14201*
select instrument from Table where time like "14201*"
select instrument from Table where time like "14201*       
select instrument from Table where time like"14201*"

These work:
select instrument from Table where time=1418234533892319745
select instrument from Table where instrument like "6E*"

These do not work either:
select instrument from Table where time > 124400000
select instrument from Table where time > 124400
select instrument from Table where time < 1    
select instrument from Table where time < 1 

Some good resource I found:
http://www.timestored.com/b/forums/topic/string-functions-like-search-replace-regex/
http://www.kx.com/q/d/kdb+1.htm

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.