Skip to content

pj

Plus join

x pj y     pj[x;y]

Where

  • x and y are tables
  • y is keyed
  • the key columns of y are columns of x

returns x and y joined on the key columns of y. If x is a table name given as a symbol, pj updates that table in place.

pj adds matching records in y to those in x by adding the values of their common non-key columns. The common columns must have types that support addition.

For each record in x:

  • if y has a matching record, pj adds it to the x record
  • if y has no matching record, pj leaves the common columns unchanged and sets new columns to zero
q)show x:([]a:1 2 3;b:`x`y`z;c:10 20 30)
a b c
------
1 x 10
2 y 20
3 z 30

q)show y:([a:1 3;b:`x`z]c:1 2;d:10 20)
a b| c d
---| ----
1 x| 1 10
3 z| 2 20

q)x pj y
a b c  d
---------
1 x 11 10
2 y 20 0
3 z 32 20

In the preceding example, pj is equivalent to x+0^y[`a`b#x]: compute the value of y on the a and b columns of x, fill the result with zeros, and add it to x.


Joins

Q for Mortals §9.9.6 Plus Join