LATEST VERSION: 8.2.7 - CHANGELOG
Pivotal GemFire® v8.2

SELECT Statement Query Results

SELECT Statement Query Results

The result of a SELECT statement is a collection that implements the SelectResults interface or it is UNDEFINED.

The SelectResults returned from the SELECT statement is either a collection of objects or a Struct collection containing the objects. (See also the online API documentation for Query.)

Because a SELECT statement returns a result, it can be composed with other expressions like the following example:
(SELECT DISTINCT * FROM /portfolios WHERE status = 'active').iterator

A collection of objects is returned in two cases:

  • When only one expression is specified by the projection list and that expression is not explicitly specified using the fieldname:expression syntax

  • When the SELECT list is * and a single collection is specified in the FROM clause
Table 1. Matrix of SelectResults Contents Based on SELECT and FROM Clause Specifications

SELECT

FROM

* Single Expressions Multiple Expressions
single expression Objects

Objects. (Struct if the projection specifies a field name.)

Struct
multiple expressions Struct

Objects. (Struct if the projection specifies a field name.)

Struct

When a Struct is returned, the name of each field in the Struct is determined as follows:

  • If a field is specified explicitly using the fieldname:expression syntax, the fieldname is used.
  • If the SELECT projection list is * and an explicit iterator expression is used in the FROM clause, the iterator variable name is used as the field name.
  • If the field is associated with a region or attribute path expression, the last attribute name in the expression is used.

If names can not be decided based on these rules, arbitrary unique names are generated by the query processor.

These examples show how the projections and FROM clause expressions are applied.

SELECT <*> FROM <single expression> SELECT DISTINCT *

FROM /portfolios

WHERE status ='active'

Returns the Collection of active portfolios objects.
SELECT <single expression> FROM <multiple expression> (without fieldName mentioned) IMPORT javaobject.Position; SELECT DISTINCT secId

FROM /portfolios,

positions.values TYPE Position

WHERE status ='active'

Returns the Collection of secIds (CacheableString

objects) from the positions of active portfolios.

SELECT <single expression> FROM

<multiple expression> (with fieldName mentioned)

IMPORT javaobject.Position;SELECT DISTINCT secIdFieldName:secId

FROM /portfolios, positions.values TYPE Position

WHERE status ='active'

Returns struct<secIdField: CacheableString> for the active portfolios. (Compare to the results for the prior query.)
SELECT <*> FROM <multiple expression>

IMPORT javaobject.Position; SELECT DISTINCT *

FROM /portfolios, positions.values TYPE Position

WHERE status = 'active'

Returns a Collection of struct<portfolios: Portfolio, values: Position> for the active portfolios.

SELECT <multiple expression> FROM <multiple expression>

IMPORT javaobject.Position;

SELECT DISTINCT pflo, posn

FROM /portfolios pflo, positions posn TYPE Position

WHERE pflo.status = 'active'

Returns a Collection of struct<pflo: Portfolio, posn: Position> for the active portfolios.