def as_sql(self, qn, connection):
            lhs, lhs_params = self.process_lhs(qn, connection)
            rhs, rhs_params = self.process_rhs(qn, connection)
            params = lhs_params + rhs_params
            table = self.lhs.alias
            pk_name = qn.query.model._meta.pk.name
            table_dot_pk_name = "%s.%s" % (table, pk_name)
            return "{table_dot_pk_name} IN (" \
                   "SELECT DISTINCT tmp_table.{pk_name} " \
                   "FROM {table} AS tmp_table " \
                   "JOIN ( " \
                   "SELECT tmp_table2.{pk_name} AS id, unnest({arrayfield_name}::text[]) AS unnest " \
                   "FROM {table} AS tmp_table2) AS embedded_table ON embedded_table.{pk_name}=tmp_table.{pk_name} " \
                   "WHERE embedded_table.unnest {comparator} %s)".format(table_dot_pk_name=table_dot_pk_name,
                                                                         pk_name=pk_name, table=table,
                                                                         arrayfield_name=lhs,
                                                                         comparator=self.comparator) % (
                       rhs, ), params
Calculate additional variables for use in the build (called by gyp).
dataset/ETHPy150Open niwinz/djorm-pgarray/djorm_pgarray/fields.py/AnyBaseLookup.as_sql--crossover with--dataset/ETHPy150Open pyokagan/gyp/pylib/gyp/generator/analyzer.py/CalculateVariables