簡體   English   中英

BigQuery 字符串格式為 json

[英]BigQuery string-formatting to json

以下是在 BigQuery 中傳遞給 json 的所有值類型的完整列表嗎? 我通過反復試驗得到了這個,但未能在文檔中找到它:

select
    NULL as NullValue,
    FALSE as BoolValue,
    DATE '2014-01-01' as DateValue,
    INTERVAL 1 year as IntervalValue,
    DATETIME '2014-01-01 01:02:03' as DatetimeValue,
    TIMESTAMP '2014-01-01 01:02:03' as TimestampValue,
    "Hello" as StringValue,
    B"abc" as BytesValue,
    123 as IntegerValue,
    NUMERIC '3.14' as NumericValue,
    3.14 as FloatValue,
    TIME '12:30:00.45' as TimeValue,
    [1,2,3] as ArrayValue,
    STRUCT('Mark' as first, 'Thomas' as last) as StructValue,
    [STRUCT(1 as x, 2 as y), STRUCT(5 as x, 6 as y)] as ArrayStructValue,
    STRUCT(1 as x, [1,2,3] as y, ('a','b','c') as z) as StructNestedValue

{
  "NullValue": null,
  "BoolValue": "false", // why not just false without quotes?
  "DateValue": "2014-01-01",
  "IntervalValue": "1-0 0 0:0:0",
  "DatetimeValue": "2014-01-01T01:02:03",
  "TimestampValue": "2014-01-01T01:02:03Z",
  "StringValue": "Hello",
  "BytesValue": "YWJj",
  "IntegerValue": "123",
  "NumericValue": "3.14",
  "FloatValue": "3.14",
  "TimeValue": "12:30:00.450000",
  "ArrayValue": ["1", "2", "3"],
  "StructValue": {
    "first": "Mark",
    "last": "Thomas"
  },
  "ArrayStructValue": [
    {"x": "1", "y": "2"},
    {"x": "5", "y": "6"}
  ],
  "StructNestedValue": {
    "x": "1",
    "y": ["1", 2", "3"],
    "z": {"a": "a", b": "b", "c": "c"}
  }
}

老實說,在我看來,除了null值和數組[]或 struct {}容器之外,所有內容都是字符串封閉的,這似乎有點奇怪。

根據這份文件,json 建立在兩個結構上:

名稱/值對的集合。 在各種語言中,這被實現為 object、記錄、結構、字典、hash 表、鍵控列表或關聯數組。

有序的值列表。 在大多數語言中,這被實現為數組、向量、列表或序列。

SELECT 查詢的結果為 json 格式,其中 [] 表示數組數據類型,{} 表示 object 數據類型,雙引號 (" ") 表示查詢本身中的字符串值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM