6

I want to ensure all values in column x are no smaller than 0.5, so I do:

update x:max (x 0.5) from myTable

But this gives an error (in Studio For KDB+):

An error occurred during execution of the query.
The server sent the response:
type
Studio Hint: Possibly this error refers to wrong type, e.g `a+1

What's wrong?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
mchen
  • 9,808
  • 17
  • 72
  • 125

3 Answers3

9

You can try using |

q)update x|0.5 from myTable
WooiKent Lee
  • 1,301
  • 6
  • 4
3

It should work. It worked for me. This is the query I used for testing:

update x:max(x;0.5) from myTable

-- Check semicolon in max function

Jean-Paul
  • 19,910
  • 9
  • 62
  • 88
Rahul
  • 3,914
  • 1
  • 14
  • 25
  • Very nice - it hadn't occurred to me that this would work, but it does. Is just as fast as the (admittedly more idiomatic) `x|.5` – mollmerx Apr 22 '14 at 00:10
1

Try the kdb vector conditional its similar to case-when in SQL:

q)t:([] a:6?.9)

q)t
a
---------
0.4237094
0.5712045
0.8705158
0.2075746
0.8549775
0.3951729

q)update ?[a<0.5;0.5;a] from t
a
---------
0.5
0.5712045
0.8705158
0.5
0.8549775
0.5
q)
Ryan Hamilton
  • 2,601
  • 16
  • 17
  • Vector conditional is unnecessary for this simple case, less readable and, on my machine, 4 times slower. – mollmerx Apr 17 '14 at 16:10