“扳手Python客户端”;绑定参数记录错误的无效值";
我试图在扳手中执行select语句,并出现以下错误:“扳手Python客户端”;绑定参数记录错误的无效值";,python,google-cloud-platform,google-cloud-spanner,Python,Google Cloud Platform,Google Cloud Spanner,我试图在扳手中执行select语句,并出现以下错误: InvalidArgument: 400 Invalid value for bind parameter record: Expected STRUCT<Msg_id STRING> 如您所见,第1行的requested\u msg\u id的值是一个字符串。然后在第6行,我将Msg_Id定义为字符串绑定参数。有人能看到我遗漏了什么吗?在SQL中,您说参数“record”是一个带有Msg_id(@record.Msg_id)的
InvalidArgument: 400 Invalid value for bind parameter record: Expected STRUCT<Msg_id STRING>
如您所见,第1行的
requested\u msg\u id
的值是一个字符串。然后在第6行,我将Msg_Id
定义为字符串绑定参数。有人能看到我遗漏了什么吗?在SQL中,您说参数“record”是一个带有Msg_id(@record.Msg_id)的结构
您还说param'record'的类型是一个具有字符串'Msg_id'值的结构(第5、6和15行)
但是,为参数'record'(第1行和第14行)传递的值是一个简单的字符串,而不是结构,因此出现了错误
您需要说参数是SQL中的一个简单字符串(比如@Msg_id),并在第15行中指定类型为字符串。。。(如果不需要定义记录类型,会更简单)
或者将参数值创建为结构
requested_msg_id = str(msg['Message Id'])
rc = ResultCode.SUCCESS
## SELECT MessageSender, Message FROM MESSAGE_STORE where MessageId = msg_id
record_type = param_types.Struct([
param_types.StructField('Msg_id', param_types.STRING)
])
with self.client.snapshot() as snapshot:
try:
results = snapshot.execute_sql(
"SELECT MessageSender, Message from MESSAGE_STORE "
"WHERE MessageId = @record.Msg_id LIMIT 1",
params={'record' : (requested_msg_id)},
param_types={'record' : record_type})
except Exception as fetch_exception:
rc = ResultCode.ERR_NO_MSG_FOUND
# results is an interator
for row in results:
if row:
output = "{ 'Message Id':" + requested_msg_id + ", 'Sender':" + row[1] + ", 'Message':" + row[2] + ", 'Result Code':" + str(rc.value) + "}"