Search code examples
kdb

Is it possible to set and reuse variables in the kdb select statement?


I would like to define some variables in my select statement. For example, here I want to define bid, ask as a modified value of the original value stored in the table (this code won't work):

select ts,ticker,bid:(bid1_price*1e-4),ask:(sl1_price*1e-4),wt:((next ts) - ts),spread:(ask - bid),wtspread:(((next ts) - ts) wavg (ask - bid)) from md where...

How can I define variables in the select statement?


Solution

  • Create your bid and ask columns first, then use them in the update...

    update wt:((next ts) - ts), spread:(ask - bid), wtspread:(((next ts) - ts) wavg (ask - bid)) by date from select ts, ticker, bid:(bid1_price*1e-4), ask:(sl1_price*1e-4) from md where...