Replace string

Hi, I have problem with replacing string “HONGKONG” to “HK” in thesample table: mytable:( mydesc:HONGKONGSHANGHAINEWYORK; myid:1 2 3 ) I got the error message "Possibly this error refers to wrong type,e.g a+1" when I run the following statement: select ssr[mydesc;“HONGKONG”;“HK”], id from mytable I tried to do casting, e.g. “s”$ but it doesn’t work. Thanks. Nick

q) ?select ssr[;“HONGKONG”;“HK”] each string mydesc, myid from mytable ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

mydesc ? ? myid


“HK” ? ? ? 1 ??

“SHANGHAI” 2 ??

“NEWYORK” ?3 ??

you could also do
update mydesc:HK from mytable where mydesc=HONGKONG

to keep the type

Regards,

  Attila

I appreciate all your help. It works well.On Dec 11, 2:54?pm, Attila Vrabecz <attila.vrab…> wrote:> you could also do> update mydesc:HK from mytable where mydesc=HONGKONG> to keep the type>> Regards,> ? Attila> On 11 Dec 2009, at 19:50, Charles Skelton wrote:>>>> > q) ?select ssr[;“HONGKONG”;“HK”] each string mydesc, myid from mytable ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?> > mydesc ? ? myid> > ---------------> > “HK” ? ? ? 1 ?> > “SHANGHAI” 2 ?> > “NEWYORK” ?3 ?>> > On Fri, Dec 11, 2009 at 8:47 PM, Ninja Li <nickli2…> wrote:> > Hi,>> > ? I have problem with replacing string “HONGKONG” to “HK” in the> > sample table:>> > ? ? mytable:( mydesc:HONGKONGSHANGHAINEWYORK; myid:1 2 3 )&gt;&gt; &gt; ? I got the error message "Possibly this error refers to wrong type,&gt; &gt; e.g a+1" when I run the following statement:>> > ? select ssr[mydesc;“HONGKONG”;“HK”], id from mytable>> > ? I tried to do casting, e.g. “s”$ but it doesn’t work.>> > ? Thanks.>> > ? Nick>> > –>> >

Submitted via Google Groups</nickli2…></attila.vrab…>

I have a similar issue, is there a better way to do this using update? Assume that “.” could be at any position.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures}

q)bt:([] s:BRK.BBRK.A; id:1 2)q)bt s id -------- BRK.B 1 BRK.A 2 q)ct:select ssr[;".";"-"] each string s from bt q)ct s ------- "BRK-B" "BRK-A"

Select and update will have similar performance.

If you have a high number of repeating items and a large table you can greatly benefit from .Q.fu.

http://code.kx.com/wiki/DotQ/DotQDotfu

This will run your function over the distinct values and then reconstruct your result.

q)N:10000000;

q)bt:( s:N?BRK.BBRK.A`BRK.C; id:N?10)

q)\ts ct:select ssr[;“.”;“-”] each string s from bt 

3213 227109904

q)\ts ct:select .Q.fu[{ssr[;“.”;“-”] each string x}]s from bt 

89 100664320