在Cosmos DB中使用关键字作为别名

问题描述 投票:0回答:1

我想使用关键字order作为SELECT子句中表达式的别名。

要复制,请将以下内容插入Cosmos DB集合中。

{
    "name": "John Doe"
}

以下查询工作正常

SELECT 
    c.name 
  , c["order"]    
  , c["order"] ?? "defaultValue" 
  , c["order"] ?? "defaultValue" as order2
FROM c
WHERE c.name = 'John Doe'

此操作失败,因为我使用了关键字order

SELECT 
    c.name 
  , c["order"]    
  , c["order"] ?? "defaultValue" 
  , c["order"] ?? "defaultValue" as order2
  , c["order"] ?? "defaultValue" as order
FROM c
WHERE c.name = 'John Doe'

我曾尝试使用方括号,双引号和单引号将别名括起来,例如SQL Server。

azure-cosmosdb alias keyword reserved-words
1个回答
0
投票

据我所知,cosmos db仅支持查询使用保留字的字段名称。

SELECT c["top"] FROM c

恐怕您不能在别名上使用保留字,因为它不能正确地识别为平滑的SQL语句。另外,我也认为这种方法会引起歧义,这在SQL中是极不推荐的。

© www.soinside.com 2019 - 2024. All rights reserved.