single

single, selector

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

def process single(value: any): any

For groups with only one element, single returns the value of that element. For empty groups, it returns the default value of the data type. For groups with more than one element, single fails.

Examples

table T = with
  [| as A, as B |]
  [| 1,    "a"  |]
  [| 2,    "b"  |]
  [| 3,    "c"  |]

table G[gdim] = by T.A

where T.A != 3
  show table "" a1b4 with
    gdim
    single(T.B)
    group by gdim

The above code results in the following table:

gdim single(T.B)
1 a
2 b
3

(Notice that the value for 3 is the empty text value – the default value for text.)

default can be used to specify the default value to use when the group is empty. For example, single(T.B) default "x" would result in the following table:

gdim single(T.B)
1 a
2 b
3 x

Errors

This selector fails when the group contains more than one element.

Remarks

This selector cannot be used with sort.

See also

User Contributed Notes
0 notes + add a note