2014-06-16 35 views
3
gql_query.query_string = "SELECT * FROM <entity> where `timestamp` <= datetime('2014-06-05 00:00:00')" 
gql_query.allow_literal = True 
resp = datastore.run_query(req) 
results = [entity_result.entity 
      for entity_result in resp.batch.entity_result] 

上的时间戳字段查询时当运行上述查询它如下产生错误错误:googledatastore包:与日期时间函数

ERROR:root:Error while doing datastore operation 
ERROR:root:RPCError: runQuery Invalid datetime text (does not match pattern): &quot;2014-06-05 00:00:00&quot; 
ERROR:root:HTTPError: 400 Bad Request 

回答

5

Cloud Datastore GQL使用RFC 3339 section 5.6表示日期时间字符串。在这种情况下,你需要使用一个“T”的日期和时间之间,而不是一个空格和一个“Z”追加到字符串的结尾:

SELECT * FROM <entity> WHERE `timestamp` <= datetime('2014-06-05T00:00:00Z') 

上合成文字的完整文档,包括多有关datetime文字的详细信息,可以找到here

+0

谢谢。这工作!我使用的是与App Engine API相同的查询。它在那里工作。 –

+0

是的,Python/App Engine GQL与Cloud Datastore GQL略有不同。您可以在这里查看差异摘要:https://developers.google.com/datastore/docs/apis/gql/gql_reference#unsupported_features_and_behavior_differences_from_mysqlpython_gql –