Я пытаюсь выполнить оператор выбора в Spanner и получить эту ошибку:
InvalidArgument: 400 Invalid value for bind parameter record: Expected STRUCT<Msg_id STRING>
Я не могу понять, почему он жалуется на параметр bind, потому что код определяет параметр bind как STRING.
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) + "}"
Как видите, значение requested_msg_id
в строке 1 является строкой. Затем в строке 6 я определяю Msg_Id
как параметр связывания STRING. Кто-нибудь может увидеть, что мне не хватает?