About the query language for Azure Digital Twins
Recall that the center of Azure Digital Twins is the twin graph, constructed from digital twins and relationships.
This graph can be queried to get information about the digital twins and relationships it contains. These queries are written in a custom SQL-like query language, referred to as the Azure Digital Twins query language. This language is similar to the IoT Hub query language with many comparable features.
This article describes the basics of the query language and its capabilities. For more detailed examples of query syntax and how to run query requests, see Query the twin graph.
About the queries
You can use the Azure Digital Twins query language to retrieve digital twins according to their...
- properties (including tag properties)
- properties of the relationships
The Query language reference can be found under Reference in the left table of contents for the Azure Digital Twins documentation. You can also go directly to the reference sections using the links below:
Considerations for querying
When writing queries for Azure Digital Twins, keep the following considerations in mind:
Remember case sensitivity: All Azure Digital Twins query operations are case-sensitive, so take care to use the exact names defined in the models. If property names are misspelled or incorrectly cased, the result set is empty with no errors returned.
Escape single quotes: If your query text includes a single quote character in the data, the quote will need to be escaped with the
\character. Here's an example that deals with a property value of D'Souza:
SELECT * FROM DIGITALTWINS WHERE Name = 'D\'Souza'
After making a change to the data in your graph, there may be a latency of up to 10 seconds before the changes will be reflected in queries.
Learn how to write queries and see client code examples in Query the twin graph.