4

Looked at all the documentation. Why is this not working? Loaded sp.q sample file given with KDB distribution. I am unable to figure out whats wrong with this statement.

q) \l sp.q
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 200

q)trade:update size:300 from trade where sym=`c,price>71
'par
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 200

2 Answers 2

4

trade is a partitioned table, which is why this is failing. what exactly are you trying to do? if you want to create a edited copy of the data in memory, you need something like

q)t:update size:300 from(select from trade)where sym=`c,price>71
q)t
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 300
q)

if you want to change the data on disk, that's quite hard in the general case. in this specific case, you can do it like this:

q){.Q.dd[.Q.par[`:.;x;`trade];`]set update size:300 from(select from trade where date=x)where sym=`c,price>71}2007.07.23
`:./2007.07.23/trade/
q)\l .
q)trade
date       sym time         price    size
-----------------------------------------
2007.07.23 a   04:48:52.665 73.53941 1000
2007.07.23 a   04:48:52.675 81.73358 600
2007.07.23 a   04:48:52.725 78.79526 900
2007.07.23 a   04:48:52.735 79.59502 600
2007.07.23 b   04:48:52.655 84.59765 200
2007.07.23 b   04:48:52.685 98.36199 500
2007.07.23 b   04:48:52.705 97.49875 700
2007.07.23 c   04:48:52.645 61.48308 900
2007.07.23 c   04:48:52.695 61.53192 700
2007.07.23 c   04:48:52.715 71.95405 300
q)
Sign up to request clarification or add additional context in comments.

Comments

2

The table is partitioned by date. You are required to specify a date to execute the query over, e.g.

trade:update size:300 from trade where sym=`c,price>71, date within (<d1>;<d2>)

3 Comments

I might be wrong, but shouldn't he be using a backtick before trade rather than just trade, so his table would get modified in place rather than copied?
No, what he's doing in fine, though this would also work: update size:300 from `trade where sym=`c,price>71, date within (<d1>;<d2>)
you can't update partitioned tables at all, with or without either backticks or date conditions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.