ExecuteSqlRequest params only takes strings
AkanshDivker opened this issue · 1 comments
AkanshDivker commented
I don't know if this is expected behaviour or if I'm doing something wrong, but I'm trying to migrate to using the SpannerAsyncClient API. When passing the params object to ExecuteSqlRequest, I get a parsing error if the values in params are not all strings. Is this expected behaviour? This wasn't the case with the high-level API.
On another note, values returned from queries are not their correct types even though the metadata lists their correct types.
Error:
google.api_core.exceptions.FailedPrecondition: 400 Could not parse number_value: 0
as INT64
Code:
sql = """
SELECT dream_id, title, timestamp, tags, tag_ids, types
FROM RecentDreams
WHERE user_id = @user_id AND timestamp <= @timestamp AND timestamp >= @max_timestamp
ORDER BY timestamp DESC
LIMIT @limit OFFSET @offset
"""
params = {
"user_id": user_id,
"timestamp": timestamp,
"max_timestamp": max_timestamp,
"limit": page_size,
"offset": start_offset,
}
param_types_dict = {
"user_id": param_types.STRING,
"timestamp": param_types.TIMESTAMP,
"max_timestamp": param_types.TIMESTAMP,
"limit": param_types.INT64,
"offset": param_types.INT64,
}
request = ExecuteSqlRequest(
session=session.name,
transaction=transaction,
sql=sql,
params=params,
param_types=param_types_dict ,
)
result = await self.spanner.execute_sql(request=request)
The above works without error if page_size
and start_offset
are passed as strings instead of integers.