Skip to main content
Version: Next

DISTINCT ATTRIBUTE VALUES

DISTINCT ATTRIBUTE VALUES ( objectField ; path ; valuesArray )

ParameterTypeDescription
objectFieldFieldObject field from which to get the list of distinct attribute values
pathTextPath of attribute whose distinct values you want to get
valuesArrayText array, Array integer, Boolean array, Date array, Time arrayDistinct values in attribute path

Description

The DISTINCT ATTRIBUTE VALUES command creates and populates the valuesArray with non-repeated (unique) values coming from the path attribute in the objectField field for the current selection of the table to which this field belongs. Note that objectField must be of the Object type, otherwise an error is returned. The command can be used with indexed or non-indexed fields.

Pass a valid attribute path in path. Use the standard dot notation to define paths to nested attributes, for example "company.address.number". Keep in mind that object attribute names are case-sensitive.

The array you passed in valuesArray must be of the same type as the values stored in the attribute path. Values must be scalar and can be of the Text, number, Boolean, Date, or Time type (pointers, objects, BLOBs or images are not supported). Make sure that all field attribute values are of the same type; otherwise, an error is returned. For example, if the path attribute contains "Monday" in one record and 10125 in another record, an error will be returned.

If the command is called from within a transaction, records created during the transaction are taken into account.

After the call, the size of the array is equal to the number of distinct values found in the selection. The command does not change the current selection or the current record.

Using the .length virtual property

You can use the "length" virtual property with this command. It is automatically available for all attributes of the array type, and provides the size of the array, i.e. the number of elements it contains. This property is designed to be used in queries (see QUERY BY ATTRIBUTE). You can also use it with the DISTINCT ATTRIBUTE VALUES command to get the different array sizes for an attribute.

Example

Your database contains a [Customer]full_Data object field with 15 records:

If you execute this code:

 ARRAY LONGINT(aLAges;0)
 ARRAY LONGINT(aLAgesChild;0)
 ARRAY LONGINT(aLChildNum;0)
 ALL RECORDS([Customer])
  //get the distinct values for the "age" attribute
 DISTINCT ATTRIBUTE VALUES([Customer]full_Data;"age";aLAges)
  //get the distinct values for the "age" attribute within the "Children" array
 DISTINCT ATTRIBUTE VALUES([Customer]full_Data;"Children[].age";aLAgesChild)
  //get the distinct numbers of children by using the length virtual property
 DISTINCT ATTRIBUTE VALUES([Customer]full_Data;"Children.length";aLChildNum)

The aLAges array receives the following elements:

ElementValue
133
235
336
440
542
644
752
854
960

The aLAgesChild array receives the following elements:

ElementValue
12
23
34
45
56
610
712
814
915
1016

The aLChildNum array receives the following elements:

ElementValue
11
22
33

See also

DISTINCT ATTRIBUTE PATHS