Why properties referenced in an equality (EQUAL) o

2019-09-05 23:39发布

https://developers.google.com/appengine/docs/java/datastore/projectionqueries

Why a projected query such as this : SELECT A FROM kind WHERE A = 1 not supported ?

2条回答
贪生不怕死
2楼-- · 2019-09-06 00:30

Because it makes no sense. You are asking

SELECT A FROM kind WHERE A = 1

so, give me A where A = 1. Well, you already know that A = 1. It makes no sense for DB to allow that.

The IN query is internally just a series of equals queries merged together, so the same logic applies to it.

查看更多
Ridiculous、
3楼-- · 2019-09-06 00:37

The reasoning behind this could be that since you already have the values of the properties you are querying you don't need them returned by the query. This is probably a good thing in the long run, but honestly, it's something that App Engine should allow anyway. Even if it didn't actually fetch these values from the datastore, it should add them to the entities returned to you behind the scenes so you can go about your business.

Anyway, here's what you can do...

query = MyModel.query().filter(MyModel.prop1 == 'value1', MyModel.prop2 == 'value2)
results = query.fetch(projection=[MyModel.prop3])
for r in results:
  r.prop1 = 'value1'  # the value you KNOW is correct
  r.prop2 = 'value2'

Again, would be nice for this to happen behind the scenes because I don't think it's something anybody should ever care about. If I mention a property in a projection list, I'm already stating that I want that property as part of my entities. I shouldn't have to do any more computation to get that to happen.

On the other hand, it's just an extra for-loop. :)

查看更多
登录 后发表回答