Azure DocumentDB - Part 6 (DocumentDB 中的 SQL 語法 1)Microsoft Azure DocumentDB 可以讓開發人員使用熟悉的 SQL 語法來查詢 json 文件,大大降低了開發上的進入門檻
SELECT 是必要的,其他皆可省略純量運算式
SELECT { id: 1, name: 'yowko'}
隱性參數變數
若未提供索引鍵,會自動建立
隱性參數變數$1,多個物件就會有多個,數字遞增
別名( alias )
可以使用別名( alias )來重新命名回傳 JSON
物件和陣列建立
SELECT [f.address.city, f.address.state] AS CityState FROM Families f
[
     {
       "CityState": [
         "seattle", 
         "WA"
       ]
     }, 
     {
       "CityState": [
         "NY", 
         "NY"
       ]
     }
]
VALUE 關鍵字
["Hello World"]
{$1: "Hello World"}
* 運算子[FROM <from_specification>] 非必要e.g.
SELECT f.id FROM Families AS forSELECT f.id FROM Families f
e.g.
SELECT id FROM Families f是無效的
e.g.
SELECT * FROM Families.children
address.state 值,SELECT * FROM Families.address.state 時就會被當做不在範圍內排除WHERE <filter_condition> 非必要支援的一元( unary )運算子(處理一個運算元):+, - , ~ and NOT
支援的二元( binary )運算子(處理二個運算元)
| Type | 運算子 | 
|---|
算術|	+,-,*,/,%
位元||,&, ^, <<, >>, >>> (右移位元並補零)
邏輯|	AND, OR, NOT
比較|	=, !=, <, >, <=, >=, <>
字串|	|| 接(連)
三元 (?) 運算子
a == b ? 1 : 0
字串 及 數字
AND
-|	True|	False|	Undefined
-|-
True|	True|	False|	Undefined
False|	False|	False|	False
Undefined|	Undefined|	False|	Undefined
OR
-|	True|	False|	Undefined
-|-
True|	True|	True|	True
False|	True|	False|	Undefined
Undefined|	True|	Undefined|	Undefined
NOT
Origin|Result
-|
True|	False
False|	True
Undefined|	Undefined
不同類型比較會導致 Undefined
Undefined 就代表會被排除
-|	Undefined|	Null|	Boolean|	Number|	String|	Object|	Array
-|-
Undefined|	Undefined|	Undefined|	Undefined	|Undefined	|Undefined	|Undefined|	Undefined
Null|	Undefined|	OK|	Undefined|	Undefined|	Undefined|	Undefined|	Undefined
Boolean|	Undefined|	Undefined|	OK|	Undefined|	Undefined|	Undefined|	Undefined
Number|	Undefined|	Undefined|	Undefined|	OK|	Undefined|	Undefined|	Undefined
String|	Undefined|	Undefined|	Undefined|	Undefined|	OK|	Undefined|	Undefined
Object|	Undefined|	Undefined|	Undefined|	Undefined|	Undefined|	OK|	Undefined
Array|	Undefined|	Undefined|	Undefined|	Undefined|	Undefined|	Undefined|	OK
[] 的屬性存取子空格 、特殊字元,SQL 保留字
SELECT f["lastName"]
FROM Families f
WHERE f["id"] = "AndersenFamily"
ASC or DESC 參數