Back to Each-Left Join

Joins · Each-Left Join · Practice Question

Extend a Table with New Null Columns

Sign in to track your progress

Question

Given:

s:([] a:1 2 3; b:3 4 5)

Extend the table to add two new columns, p and q, where p is a null float (0n) and q is a null long (0Nj). Use the dictionary:

d:`p`q!(0n;0Nj)

Expected result:

a b p q
-------
1 3
2 4
3 5

Solution

s ,\: d

Alternative Solution

.Q.ff[s;enlist d]

Explanation

,\: is each-left join — it pairs the same fixed right-hand argument against every row on the left. Here the right-hand argument is a single dictionary, d, representing one "row" of new columns (p and q, both null). Joining that dictionary against every row of s in turn adds p and q to every row, each holding the same null value, since there's nothing row-specific in d to vary per row.

.Q.ff ("fill fields") is a purpose-built utility for exactly this: extending a table to match a template row's schema, filling in any new columns with that template's values. enlist d wraps the single dictionary into a one-row table, since .Q.ff expects a table to extend s with, not a bare dictionary — the result is the same either way.