select ( $select_expression, $opt )

The Select operation returns a set of attributes for ItemNames that match the select expression. Select is similar to the standard SQL SELECT statement.

The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB automatically adjusts the number of items returned per page to enforce this limit. For example, if the client asks to retrieve 2500 items, but each individual item is 10 kB in size, the system returns 100 items and an appropriate NextToken so the client can access the next page of results.

For information on how to construct select expressions, see Using Select to Create Amazon SimpleDB Queries in the Developer Guide.

Access

public

Parameters

Parameter

Type

Required

Description

$select_expression

string

Required

The expression used to query the domain.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • NextToken - string - Optional - A string informing Amazon SimpleDB where to start the next list of ItemNames .
  • ConsistentRead - boolean - Optional - Determines whether or not strong consistency should be enforced when data is read from SimpleDB. If true , any data previously written to SimpleDB will be returned. Otherwise, results will be consistent eventually, and the client may not see data that was written immediately before your read.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Select data from a SimpleDB domain.

// Instantiate
$sdb = new AmazonSDB();
$response = $sdb->select('SELECT * FROM `example-domain`');

// Success?
var_dump($response->isOK());
Result:
bool(true)

Select more data by passing a NextToken parameter.

The best way to collect more data is to continue to loop until there are no more NextToken values remaining. Here, we use a do-while loop.

// Instantiate
$sdb = new AmazonSDB();
$select_expression = 'SELECT * FROM `example-domain`';
$next_token = null;

do {
	if ($next_token)
	{
		$response = $sdb->select($select_expression, array(
			'NextToken' => $next_token,
		));
	}
	else
	{
		$response = $sdb->select($select_expression);
	}

	// ...Store data!

	$next_token = isset($response->body->SelectResult->NextToken)
		? (string) $response->body->SelectResult->NextToken
		: null;
}
while ($next_token);

echo '.';

Related Methods

Source

Method defined in services/sdb.class.php | Toggle source view (7 lines) | View on GitHub

public function select($select_expression, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['SelectExpression'] = $select_expression;
    
    return $this->authenticate('Select', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback