update where symbol length less than 3 characters KDB+/Q

Viewed 201

I have a table like this:

test:([]column1:`A`B`C`D`E;column2:`Consumer`RealEstate`27`85`Technology)

I need to write an update query where the character count of column2 is 2 or less, but I couldn't find any way to reference the character length of a symbol to use in a where clause. How would I write a query like that so my result is the following?

test:([]column1:`A`B`C`D`E;column2:`Consumer`RealEstate`NewCategory`NewCategory`Technology)
2 Answers

One way to accomplish what you want is to convert the symbols into strings (i.e. lists of chars) and apply the where clause to the count of each of those strings:

update column2:`NewCategory from `test where 3>count each string column2

(using a backtick on the table name here, assuming you want to apply the change in place)

Another option is to use a vector conditional

update column2:?[3>count each string column2;`NewCatergory;column2] from test
Related