Skip to content

- Subtract

x-y     -[x;y]

Where x and y are numerics or temporals, returns their difference.

q)3 4 5-2
1 2 3

q)2000.11.22 - 03:44:55.666
2000.11.21D20:15:04.334000000

Implicit iteration

Subtract is an atomic function.

q)(10;20 30)-(2;3 4)
8
17 26

It applies to dictionaries and tables.

q)k:`k xkey update k:`abc`def`ghi from t:flip d:`a`b!(10 -21 3;4 5 -6)

q)d-1
a| 9 -22 2
b| 3 4   -7

q)d-`b`c!(10 20 30;1000*1 2 3)  / upsert semantics
a| 10    -21   3
b| -6    -15   -36
c| -1000 -2000 -3000

q)t-100
a    b
---------
-90  -96
-121 -95
-97  -106

q)k-k
k  | a b
---| ---
abc| 0 0
def| 0 0
ghi| 0 0

Add is generally faster than Subtract.

Range and domains

    b g x h i j e f c s p m d z n u v t
----------------------------------------
b | i . i i i j e f i . p m d z n u v t
g | . . . . . . . . . . . . . . . . . .
x | i . i i i j e f i . p m d z n u v t
h | i . i i i j e f i . p m d z n u v t
i | i . i i i j e f i . p m d z n u v t
j | j . j j j j e f j . p m d z n u v t
e | e . e e e e e f e . p m d z n u v t
f | f . f f f f f f f . f f z z f f f f
c | . . . . . . . f . . p m d z n u v t
s | . . . . . . . . . . . . . . . . . .
p | p . p p p p p f p . n . . . p p p p
m | m . m m m m m f m . . i . . p p p p
d | d . d d d d d z d . . . i . p p p p
z | z . z z z z z z z . . . . f p z z z
n | n . n n n n n f n . p p p p n n n n
u | u . u u u u u f u . p p p z n u v t
v | v . v v v v v f v . p p p z n v v t
t | t . t t t t t f t . p p p z n t t t

Range: defijmnptuvz


Add, deltas, differ, .Q.addmonths
Datatypes, Mathematics
How to handle temporal data in q
Q for Mortals §4.9.2 Temporal Arithmetic