dongyi4170 2017-03-09 15:38
浏览 115

使用GOLANG V2 API在Google BigQuery中进行参数化查询

Im currently unable to use parameterized queries to Google BigQuery using the V2 API in GOLANG. Typically without the paramters the code to process the query would be:

database_query := client.Query(report.Query) database_query.QueryConfig.Dst = table_result job, err := database_query.Run(ctx)

assume that we dont use the named paramters. lets mock 2 parameters and append this to the request as expected from the API(https://github.com/GoogleCloudPlatform/google-cloud-go/blob/master/bigquery/query.go) :

var params [2]string
params[0] = "currency"
params[1] = "price"

ParametersL := make([]bigquery.QueryParameter, 0)
for _,element := range params {
    temp := bigquery.QueryParameter{}
    temp.Value=element
    ParametersL = append(ParametersL,temp)
}

database_query := client.Query(report.Query)
database_query.QueryConfig.Dst = table_result
database_query.QueryConfig.Parameters= ParametersL

provided you manage to squeeze the '?' into the appropriate place into the query you either get a error prompting missing , after FROM or the other ? is not recognized. The same goes for named paramters using @. Am I missing something cruzial or is the paramters not supported for GOLANG API?

  • 写回答

1条回答 默认 最新

  • doujiu8479 2017-03-09 15:43
    关注

    You need to set UseStandardSQL as part of QueryConfig, since query parameters are supported only with standard SQL. You will also need to make sure to set the Type attribute of the QueryParameters, which should be "STRING". While positional parameters are supported, of course, I would still suggest using named parameters, since they make refactoring easier if you need to modify the query string at some point.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP