def _as_sql(self, connection):
        if self._fields is not None:
            # values() queryset can only be used as nested queries
            # if they are set up to select only a single field.
            if len(self._fields or self.model._meta.concrete_fields) > 1:
                raise TypeError('Cannot use multi-field values as a filter value.')
            clone = self._clone()
        else:
            clone = self.values('pk')

        if clone._db is None or connection == connections[clone._db]:
            return clone.query.get_compiler(connection=connection).as_nested_sql()
        raise ValueError("Can't do subqueries with queries on different DBs.")

    # When used as part of a nested query, a queryset will never be an "always
    # empty" result.
Compare two entity protobuf's by key.
dataset/ETHPy150Open django/django/django/db/models/query.py/QuerySet._as_sql--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/datastore/appscale_stub_util.py/CompareEntityPbByKey