Search code examples
kdb

Set values for all records in a Kdb table based on values of other columns


I need to perform a global update on a KDB table to update two columns. For the FirstName column, I want to remove it's value for records which have empty string in the SecondName column, and for the FullName column I want to replace an encoded delimiter with a space for all rows in the table.

These need not be done in a single update statement if that helps.

update
    FirstName:$[SecondName like ""; FirstName; ""],
    FullName[FullName; " "; " "]
    from table
    }

I'm struggling with the syntax - the above is my best attempt but it doesn't work.


Solution

  • One way to achieve that in a sinlge update statement:

    q) update FirstName:?[SecondName like ""; SecondName;FirstName], FullName:ssr[;" "; " "]@'FullName from table