Kajoj
Kajoj

Reputation: 13

Azure Digital Twin forbbitten words in Query

When I execute query

SELECT Group FROM DIGITALTWINS Sensor JOIN Group RELATED Sensor.contains WHERE Sensor.$dtId='xxx’

I'm getting error

RestError: SQL query parse failed: SQL Parser Error, Line=1, Position=7, Message=mismatched input 'Group' expecting {AVG, CONTAINS, COUNT, DEVICES_JOBS, DEVICES_MODULES, DEVICES, DIGITALTWINS, RELATIONSHIPS, JOIN, MAX, MIN, RELATED, SUM, TOP, EXACT, DEFAULT, '*', IDENTIFIER}
SQL Parser Error, Line=1, Position=13, Message=mismatched input 'FROM' expecting BY See samples in http://aka.ms/adtv2query for the correct syntax.

But when I change “Group” to another word, ex “a” Query succeeded. I'm getting this same error when I use the word “Order”. I think this is because this word is used in normal SQL queries, and even if digital twins don't support it, still want to parse it and I got an error.

Where I can find a list of the forbidden words for queries?

Upvotes: 1

Views: 349

Answers (2)

asergaz
asergaz

Reputation: 1051

Here is the set of "reserved" keywords in the language:

  • ALL
  • AND
  • AS
  • ASC
  • AVG
  • BY
  • COUNT
  • DESC
  • DEVICES_JOBS
  • DEVICES_MODULES
  • DEVICES
  • ENDS_WITH
  • FALSE
  • FROM
  • GROUP
  • IN
  • IS_BOOL
  • IS_DEFINED
  • IS_NULL
  • IS_NUMBER
  • IS_OBJECT
  • IS_PRIMITIVE
  • IS_STRING
  • MAX
  • MIN
  • NOT
  • NOT_IN
  • NULL
  • OR
  • ORDER
  • SELECT
  • STARTS_WITH
  • SUM
  • TOP
  • TRUE
  • WHERE
  • IS_OF_MODEL

These words cannot be used as identifiers without enslosing them with [[ ]].

[UPDATE] See more details in the documentation: https://learn.microsoft.com/en-us/azure/digital-twins/reference-query-reserved

Upvotes: 2

Petr
Petr

Reputation: 359

I see that you have mixed single quotes: ' vs (I am not sure how they are named). Sometimes it happens when copying and pasting text.

Update: Group word (as well as any other reserved word) has to be escaped using square brackets: [[<IDENTIFIER>]].

Query:

SELECT [[Group]] FROM DIGITALTWINS Sensor JOIN [[Group]] RELATED Sensor.contains WHERE Sensor.$dtId='xxx'

Upvotes: 3

Related Questions