Im trying to create a new column(boolean) based on the string value of another column. Heres an example query I’m trying to use.
select has_name:?[not name=“”;1b;0b] from t1
Assume that t1 has a column name which is a string that contains names. Im trying to create a column “has_name” that is a boolean and checks if name exists or not.
You could use the each right (/:) iterator along with ~
select hasname: not “” ~/: name from t1
Using ~ (match) instead of = here is preferable because = requires the two strings to be the same length. ~ also has the added benefit of directly returning either 0 or 1 regardless of the length of the two strings being compared. Another way to do this without an iterator would be to use the like keyword:
update hasname: not name like “” from t1
like also has the advantage of being compatible with string patterns and wild cards, for example if you wanted to find all the people in the list with the same first name.
Also, just fyi, it’s a good idea to avoid using _ in your column names (or variables in general) as it may get confused with the drop _ operator. If you want clarity for multi-word column or variable names you could try using camel casing (e.g. hasName).