Adam Greenall
Adam Greenall

Reputation: 189

Cosmos DB SQL API - How to query a field name that uses a reserved word

I'm trying to query a collection for some documents where one of the fields happens to be named 'top'. However, I can't directly reference this column in a select statement because the name conflicts with the TOP keyword. For example:

SELECT C.code, C.top FROM c

This throws the following error - "Syntax error, incorrect syntax near 'top'."

Is there anything I can do to escape this field name, or will I have to rename the field to something else?

Upvotes: 7

Views: 4961

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

top is a reserved keyword. To escape this use [""] syntax.

SELECT  c.code,c["top"] FROM c

Upvotes: 23

Related Questions