company logo

TypeDefinition :: select - Select expression

The select operation defines the rules for calculating the derived values. The SELECT operation allows defining an implicit defined complex data type. Each operand in the operand (or attribute) list defines an property in the result data type. The SELECT allows defining any number of attributes or collection properties by defining the data type, the property name and an assignment expression defining the value for the property.

The source for a SELECT operation (calling object) in an access path is the result of the preceding operand. In a SELECT statement, the calling object is the result of the FROM operation when no grouping has been defined or the result of the GROUP BY operation otherwise. All expressions for assigning values to SELECT operands must be valid in the context of the data type of the calling object.

When an operand is a result of an operation, an operand name and data type definition have to be defined explicitly. One may omit the type definition, when the operation is defined as OSI function in the resource data base or as preloaded OSI function, which provides the type in the return value definition. The type is required, when the function is implemented as C++ function supported via OSI interface.

The operand list may contain an '*' only, which does nothing else than returning the instances as being defined in the source operand (calling object or FROM operation) for the SELECT operation. This operation does not make sense in an access path. When a SELECT statement contains a GROUP operation, the result contains all grouping attributes, but not the partition property.

Usually, the select operands may refer to grouping attributes, aggregation functions and transient attributes.

SELECT ( sex, // attribute reference

         string age = age_group, // attribute definition

         int cnt = sum(1) // named operation

         int(10,2) avr_inc = average(income) )

Grouping attributes

In order to become part of result instances, grouping attributes have to be defined explicitly in the SELECT operand (or VIEW attributes) list. One may also define operations based on grouping attributes for defining derived result attributes, but this is usually solved more comfortable by transient properties.

Aggregation functions

The SELECT statement supports aggregation functions (see also Aggregation functions). In general, aggregation functions require a collection as calling object, which must precede the aggregation function. In order to minimize collection iterations, a partition property may be assigned, which is the default calling object for all succeeding aggregation functions. When the SELECT statement contains a GROUP operation, the partition property is defined implicitly by the GROUP operation.

// optimized aggregation over children collection (no grouping)

  SELECT ( sex, name, first_name

     set<Person>  &partition = children,

     int(10,2) dev_inc = deviation(income),

     int(10,2) avr_inc = average(income) )

Transient properties

Transient properties are evaluated by an assigned operands or by means of context functions (read event handler). Operands assigned to transient properties in a VIEW definition or SELECT statement must be valid in the context of the VIEW or SELECT result data type. Transient attributes with assigned operands are evaluated when accessing transient attributes, i.e. after aggregations have been completed.

Return value:  String value ( odaba::String & )

Implementation details

odaba::String TypeDefinition  :: select (  )

When the type definition is a valid view definition the function returns a string containing the select specification. When no Select has been defined for the view, an empty string is returned. If there is no valid view definition, the function throws an exception.

In order to check, whether the type definition refers to a view, one may call isView().