1
當使用扳手python客戶端(但也許問題更普遍),似乎不可能將結構作爲參數傳遞給查詢。谷歌扳手結構作爲參數
考慮以下設置:
from google.cloud.proto.spanner.v1 import type_pb2
from google.cloud import spanner
spanner_client = spanner.Client()
instance = spanner_client.instance('myinstance')
database = instance.database('mydb')
如果我想下面的查詢翻譯成使用PARAMATERS
select * from UNNEST(ARRAY[STRUCT<foo INT64, bar INT64>(1, 2)])
這樣做
STRUCT_TYPE = type_pb2.StructType()
FOO = type_pb2.StructType.Field(name='foo', type=type_pb2.Type(code=type_pb2.INT64))
BAR = type_pb2.StructType.Field(name='bar', type=type_pb2.Type(code=type_pb2.INT64))
STRUCT_TYPE.fields.extend([FOO, BAR])
database.execute_sql('select * from UNNEST(ARRAY[@struct])',
params={'struct': [1,2]},
param_types={'struct': STRUCT_TYPE})
能給我
TypeError: Parameter to MergeFrom() must be instance of same class: expected Type got StructType.
有什麼辦法可以讓結構通過嗎?