kdb

How do we update a table column which is list type based on list indices range


How do we update a table column which is list type based on list indices range

sample table tab:([] date:2024.01.01+til 30;sym:30?`appl`msgt`googl;volume:30#(enlist 0.5+300?til 100));

Lets just work with row1 in current example so its easier

exec first volume from tab where i=0 //300

enter image description here

Now, we want to query and update the table tab such that user passes start index and end index, take that and update the volume from tab to zero 0 for that index range.

We have 300 values in volume column for first row as eg. , say user passes start:100;end:200, so here we need to make the index 100 to 200 as zero in volume column where its is first row or any row given.

I tried to solve it by indexing a list but it works for single index but not works for a range of index in update statement


Solution

  • Using . amend

    q){[start;end] .[tab;(::;`volume;start+til end-start);:;0f]}[100;200]
    

    This will set indexes 100 to 200 as 0f in every volume row.