3 out of 8 rated this helpful - Rate this topic

Query Entities (REST API)

Updated: September 13, 2011

The Query Entities operation queries entities in a table and includes the $filter and $select options.

For requests using the $select query option, the request must be made using version 2011-08-18 or newer. In addition, the DataServiceVersion and MaxDataServiceVersion headers must be set to 2.0. The Query Entities request may be constructed as follows. HTTPS is recommended. Replace myaccount with the name of your storage account, and mytable with the name of your table:

 

Method Request URI HTTP Version

GET

https://myaccount.table.core.windows.net/mytable(PartitionKey='<partition-key>',RowKey='<row-key>')?$select=<comma-separated-property-names>

https://myaccount.table.core.windows.net/mytable()?$filter=<query-expression>&$select=<comma-separated-property-names>

HTTP/1.1

The address of the entity set to be queried may take a number of forms on the request URI. For more information, see Querying Tables and Entities.

Emulated Storage Service URI

The $select query option is not currently supported by the storage emulator, but the $filter query option is supported. When making a request against the emulated storage service, specify the emulator hostname and Table service port as 127.0.0.1:10002, followed by the emulated storage account name:

 

Method Request URI HTTP Version

GET

http://127.0.0.1:10002/devstoreaccount1/mytable(PartitionKey='<partition-key>',RowKey='<row-key>')

http://127.0.0.1:10002/devstoreaccount1/mytable()?$filter=<query-expression>

HTTP/1.1

The Table service in the storage emulator differs from the Windows® Azure™ Table service in several ways. For more information, see About Development Storage and Differences between Development Storage and Cloud Storage Services.

URI Parameters

The Query Entities operation supports the query options defined by the ADO.NET Data Services Framework. For more information, see Querying the Data Service (WCF Data Services).

Request Headers

The following table describes required and optional request headers.

 

Request header Description

Authorization

Required. Specifies the authentication scheme, account name, and signature. For more information, see Authentication for the Windows Azure Storage Services.

Date or x-ms-date

Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authentication for the Windows Azure Storage Services.

x-ms-version

Optional. Specifies the version of the operation to use for this request. For more information, see Versioning for the Blob, Queue, and Table services in Windows Azure.

Request Body

None.

Sample Request

Request Syntax:
GET /myaccount/Customers()?$filter=(Rating%20ge%203)%20and%20(Rating%20le%206)&$select=PartitionKey,RowKey,Address,CustomerSince  HTTP/1.1

Request Headers:
x-ms-version: 2011-08-18
x-ms-date: Tue, 30 Aug 2011 15:25:14 GMT
Authorization: SharedKeyLite myaccount:<some key>
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
DataServiceVersion: 2.0;NetFx
MaxDataServiceVersion: 2.0;NetFx

The response includes an HTTP status code, a set of response headers, and a response body.

Status Code

A successful operation returns status code 200 (OK).

For information about status codes, see Status and Error Codes and Table Service Error Codes.

Response Headers

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

 

Response header Description

x-ms-continuation-NextPartitionKey

x-ms-continuation-NextRowKey

If the number of entities to be returned exceeds 1,000, if the server timeout interval is exceeded, or if the query crosses the partition boundary, the response header includes the x-ms-continuation-NextPartitionKey and x-ms-continuation-NextRowKey continuation headers.

For more information about using the continuation tokens, see Query Timeout and Pagination.

x-ms-request-id

This header uniquely identifies the request that was made and can be used for troubleshooting the request. For more information, see Troubleshooting API Operations.

x-ms-version

Indicates the version of the Table service used to execute the request. This header is returned for requests made against version 2009-09-19 and later.

Date

A UTC date/time value generated by the service that indicates the time at which the response was initiated.

Sample Response

Response Status:
HTTP/1.1 200 OK

Response Headers:
Content-Type: application/atom+xml;charset=utf-8
x-ms-request-id: 87f178c0-44fe-4123-a4c1-96c8fa6d9654
Date: Tue, 30 Aug 2011 15:25:14 GMT
x-ms-version: 2011-08-18
Connection: close

Response Body

The Query Entities operation returns the list of tables in the account as an WCF entity set, which is an Atom feed.

Here is a sample request URI for a Query Entities operation on a Customers table.

GET /myaccount/Customers()?$filter=(Rating%20ge%203)%20and%20(Rating%20le%206)&$select=PartitionKey,RowKey,Address,CustomerSince

And here is the response body:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="https://myaccount.table.core.windows.net/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Customers</title>
  <id>https://myaccount.table.core.windows.net/Customers</id>
  <updated>2008-10-01T15:26:13Z</updated>
  <link rel="self" title="Customers" href="Customers" />
  <entry m:etag="W/&quot;datetime'2008-10-01T15%3A26%3A04.6812774Z'&quot;">
  <id>https://myaccount.table.core.windows.net/Customers(PartitionKey='Customer03',RowKey='Name')</id>
    <title type="text"></title>
    <updated>2008-10-01T15:26:13Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Customers" href="Customers (PartitionKey='Customer03',RowKey='Name')" />
    <category term="myaccount.Customers" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:PartitionKey>Customer03</d:PartitionKey>
        <d:RowKey>Name</d:RowKey>
        <d:Address m:null="true" />
        <d:CustomerSince m:type="Edm.DateTime">2008-10-01T15:25:05.2852025Z</d:CustomerSince>
      </m:properties>
    </content>
  </entry>
</feed>

This operation can be performed by the account owner and by anyone with a shared access signature that has permission to perform this operation.

A query against the Table service may return a maximum of 1,000 entities at one time and may execute for a maximum of five seconds. If the result set contains more than 1,000 entities, if the query did not complete within five seconds, or if the query crosses the partition boundary, the response includes custom headers containing a set of continuation tokens. The continuation tokens may be used to construct a subsequent request for the next page of data. For more information about continuation tokens, see Query Timeout and Pagination.

For projection requests using the $select query option, the request must be made using version 2011-08-18 or newer. The maximum number of returned properties is 255, and all projected properties will be included in the response body even if the property is not part of the returned entity. For example, if the request includes a property that the projected entity does not contain, the missing property is marked with a null attribute. The sample response body above includes the Address property, which is not part of the projected entity, so the property is null: <d:Address m:null=”true” />

The total time allotted to the request for scheduling and processing the query is 30 seconds, including the five seconds for query execution.

Note that the right-hand side of a query expression must be a constant; you cannot reference a property on the right-hand side of the expression. See Querying Tables and Entities for details on constructing query expressions.

A query expression may not contain null values. The following characters must be encoded if they are to be used in a query string:

  • Forward slash (/)

  • Question mark (?)

  • Colon (:)

  • 'At' symbol (@)

  • Ampersand (&)

  • Equals sign (=)

  • Plus sign (+)

  • Comma (,)

  • Dollar sign ($)

Any application that can authenticate and send an HTTP GET request can query entities in a table.

You can also use the WCF Data Services Client Library to construct a query by using LINQ. For more information about supported query operations against the Table service through LINQ, see Query Operators (Table Service Support) and Writing LINQ Queries.

noteNote
Currently, the .NET Client Library throws a DataServiceRequestException when a query is executed against a resource that does not exist.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter