single

single, table creation

There are other concepts named single.
See the entire list.

The contextual keyword single modifies the by table creation statement. When the modifier single is present, the table creation fails if any group has more than 1 element. The vectors of the originating table are copied into the newly created table.

table T = with
  [| as Code |]
  [| "FR"    |]
  [| "US"    |]
  [| "UK"    |]
  [| "FR"    |] // Fails here due to duplicate

table Countries[c] = single by T.Code

show table "Countries" a1b3 with c

The vector copy and the broadcast behavior is illustrated by:

table T = with
  [| as Code, as X |]
  [| "FR",    1    |]
  [| "US",    2    |]
  [| "UK",    3    |]
  [| "DE",    4    |]

// The vector 'Country.X' is copied from 'T.X' due to 'single'
table Countries[c] = single by T.Code

// The line 'X == 4' is dropped.
show table "Countries" a1b3 with c, Countries.X 

In the above script, removing the single modifier prevents the script from compiling as Countries.X would not exist otherwise.

The single by statement is intended as an more readable alternative to a block filter that precisely removes unintended duplicates from the original table.

table T = with
  [| as Code, as X |]
  [| "FR",    1    |]
  [| "US",    2    |]
  [| "UK",    3    |]
  [| "FR",    4    |]

where T.X != 4
  table Countries[c] = single by T.Code
  Countries.X = T.X 
  show table "" a1b3 with c, Countries.X
User Contributed Notes
0 notes + add a note