Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 239
Adam Greenall Avatar asked Jun 28 '18 12:06

Adam Greenall


1 Answers

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

SELECT  c.code,c["top"] FROM c
like image 109
Sajeetharan Avatar answered Oct 02 '22 14:10

Sajeetharan