0

Consider the table:

q)trade
stock price amt  time
-----------------------------
ibm   121.3 1000 09:03:06.000
bac   5.76  500  09:03:23.000
usb   8.19  800  09:04:01.000

and the list:

q)x: 10000 20000

The following query:

q)select from trade where price < x[first where (x - price) > 100f]
'length

fails as above. How can I pass the current row value of price in each iteration of the search query?

While price[0] in the square brackets above works, that's obviously not what I want. I even tried price[i] but that gives the same error.

marital_weeping
  • 618
  • 5
  • 18
  • 1
    You are getting 'length error because 'x' and 'price' lengths are different. 'x' length is 2 and price is 3 when it goes into your function. To fix this , could you please give more details actually what you want to achieve with sample output result. – Rahul Oct 28 '15 at 08:33
  • I want price to be a scalar when its passed into the indexing function of `x` above. It's value should be the value at each row that select iterates over. `x` and `price` are meant to have different lengths. Does that make sense? – marital_weeping Oct 28 '15 at 08:36
  • so one thing is clear that in each iteration you want one price value in function. Is it same for 'x' or each price value gets compared with full 'x' ? – Rahul Oct 28 '15 at 08:40
  • I am thinking of `x` as a "vector": so if `x: 10 20` and say we are at the index `i:20` and `price[20] : 10` in my query, i want `x - price[20] : 0 10`. – marital_weeping Oct 28 '15 at 08:43
  • try this: price100f – Rahul Oct 28 '15 at 08:58
  • Thanks Rahul, although this works for the toy example above, I am not finding luck with the real problem at hand. `price` must be a scalar/atom corresponding to the current row being iterated upon. Any ideas? – marital_weeping Oct 28 '15 at 12:52
  • In above condition, price on right end is behaving exactly the same like iterating over each row. So each price value is getting substraced from full x and used in further calculation. Do you mean that you want price on the left side of comparison to be scalar as well. Someting like this : (price[i] 100f] – Rahul Oct 28 '15 at 14:06
  • Ok, i think I figured it out: `price < x[first each (where each ((x -/:price)>100f))]` seems to work. – marital_weeping Oct 29 '15 at 15:18
  • 2
    This is the same query that i mentioned before. – Rahul Oct 29 '15 at 19:41

0 Answers0