0
我想使用Python API的BigQuery標準SQL,但我無法執行在WEB UI中成功運行的查詢。BigQuery使用Python的標準SQL無法使用OFFSET關鍵字
基本上,我分裂一個字符串,然後使用OFFSET關鍵字來獲取特定索引的值。具體如下:
CASE WHEN t.depth = 1 THEN '' WHEN t.depth = 2 THEN '' WHEN t.depth = 3 THEN '' WHEN t.depth = 4 THEN '' WHEN t.depth = 5 THEN '' WHEN t.depth = 6 THEN t.curr WHEN t.depth = 7 THEN SPLIT(t.ancestry,'/')[OFFSET(6)] ELSE '' END AS level7,
CASE WHEN t.depth = 1 THEN '' WHEN t.depth = 2 THEN '' WHEN t.depth = 3 THEN '' WHEN t.depth = 4 THEN '' WHEN t.depth = 5 THEN t.curr WHEN t.depth = 6 THEN SPLIT(t.ancestry,'/')[OFFSET(5)] WHEN t.depth = 7 THEN SPLIT(t.ancestry,'/')[OFFSET(5)] ELSE '' END AS level6,
上面的代碼運行,而無需在WEB UI的問題,而使用Python API和設置useLegacySQL = False
,我收到以下錯誤
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/*************
returned "Encountered " "]" "[OFFSET(6)] "" at line 7, column 217. Was expecting: "END" ...">
任何幫助表示讚賞。
我現在試過它適用於我。你可以在這裏添加你的代碼嗎? –